diff --git a/pbc b/pbc index 8dc5ff9..2790157 100755 --- a/pbc +++ b/pbc @@ -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 }