add guard to may_select in case stdin is not a terminal

This commit is contained in:
2026-08-22 05:54:50 +02:00
parent 32e88beedc
commit f93f647504
+6 -2
View File
@@ -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
}