summaryrefslogtreecommitdiffhomepage
path: root/tests/zash/select.sh
blob: 2b6fd4705bca1a5162c3b91095a741d4d6c981e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# shellcheck disable=SC2016
# `select`, the ksh88 menu loop: the menu goes to stderr as number, tab,
# word; the prompt is PS3; the answer is a line of stdin; end of input ends
# the loop.  A number in range picks that word, anything else leaves the
# variable empty and the body still runs; a blank line only prompts again.
printf '2\n' | "$TSH" -c 'select x in alpha beta; do echo "pick [$x] [$REPLY]"; break; done' 2>/dev/null
echo "--- menu and prompt, on stderr"
printf '1\n' | "$TSH" -c 'select x in alpha beta; do break; done' 2>&1 >/dev/null | tr '\t' ' '
echo
echo "--- out of range and not a number"
printf '9\nbeta\n' | "$TSH" -c 'select x in alpha beta; do echo "pick [$x] [$REPLY]"; done' 2>/dev/null
echo "--- after the loop, the variable keeps the last pick"
printf '2\n' | "$TSH" -c 'select x in alpha beta; do break; done; echo "last [$x]"' 2>/dev/null
echo "--- a blank line only prompts again"
printf '\n1\n' | "$TSH" -c 'select x in alpha beta; do echo "ran [$x]"; done' 2>/dev/null
echo "--- no in list means the parameters"
"$TSH" -c 'set -- one two; printf "1\n" | { select x; do echo "param [$x]"; break; done; }' 2>/dev/null
echo "--- PS3 is the prompt"
printf '1\n' | PS3='which? ' "$TSH" -c 'select x in alpha beta; do break; done' 2>&1 >/dev/null | tr '\t' ' '
echo
echo "--- end of input ends the loop"
"$TSH" -c 'select x in alpha beta; do echo "body"; done < /dev/null' 2>/dev/null
echo "status $?"
echo "--- continue shows the menu again"
printf '1\n2\n' | "$TSH" -c 'select x in alpha beta; do echo "pass [$x]"; continue; done' 2>/dev/null