From f93f64750492c9a0734c21410850fbfa5f4b9904d481a09fcbf51412b83b993f Mon Sep 17 00:00:00 2001 From: Thomas Oettli Date: Sat, 22 Aug 2026 05:54:50 +0200 Subject: [PATCH] add guard to may_select in case stdin is not a terminal --- pbc | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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 }