SHA256
add guard to may_select in case stdin is not a terminal
This commit is contained in:
@@ -180,8 +180,12 @@ function may_select() {
|
|||||||
if [ -z "$value" ]; then
|
if [ -z "$value" ]; then
|
||||||
if (( $# == 1 )); then
|
if (( $# == 1 )); then
|
||||||
value=$1
|
value=$1
|
||||||
|
elif [ ! -t 0 ]; then
|
||||||
|
echo "Error: no value given and stdin is not a terminal" >&2
|
||||||
|
return 1
|
||||||
else
|
else
|
||||||
local sorted=($(printf "%s\n" "$@" | sort))
|
local sorted
|
||||||
|
readarray -t sorted < <(printf '%s\n' "$@" | sort)
|
||||||
select value in "${sorted[@]}"; do
|
select value in "${sorted[@]}"; do
|
||||||
[ -n "$value" ] && break
|
[ -n "$value" ] && break
|
||||||
done
|
done
|
||||||
@@ -190,8 +194,8 @@ function may_select() {
|
|||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
[ -z "$value" ] && return 1
|
||||||
echo "$value"
|
echo "$value"
|
||||||
return 0
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user