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