xref: /titanic_41/usr/src/lib/libshell/common/tests/select.sh (revision bfc032a14cc866ab7f34ca6fd86c240a5ebede9d)
1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#          Copyright (c) 1982-2010 AT&T Intellectual Property          #
5#                      and is licensed under the                       #
6#                  Common Public License, Version 1.0                  #
7#                    by AT&T Intellectual Property                     #
8#                                                                      #
9#                A copy of the License is available at                 #
10#            http://www.opensource.org/licenses/cpl1.0.txt             #
11#         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         #
12#                                                                      #
13#              Information and Software Systems Research               #
14#                            AT&T Research                             #
15#                           Florham Park NJ                            #
16#                                                                      #
17#                  David Korn <dgk@research.att.com>                   #
18#                                                                      #
19########################################################################
20function err_exit
21{
22	print -u2 -n "\t"
23	print -u2 -r ${Command}[$1]: "${@:2}"
24	let Errors+=1
25}
26alias err_exit='err_exit $LINENO'
27
28Command=${0##*/}
29integer Errors=0
30
31tmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
32trap "cd /; rm -rf $tmp" EXIT
33
34PS3='ABC '
35
36cat > $tmp/1 <<\!
371) foo
382) bar
393) bam
40!
41
42select i in foo bar bam
43do	case $i in
44	foo)	break;;
45	*)	err_exit "select 1 not working"
46		break;;
47	esac
48done 2> /dev/null <<!
491
50!
51
52unset i
53select i in foo bar bam
54do	case $i in
55	foo)	err_exit "select foo not working" 2>&3
56		break;;
57	*)	if	[[ $REPLY != foo ]]
58		then	err_exit "select REPLY not correct" 2>&3
59		fi
60		( set -u; : $i ) || err_exit "select: i not set to null" 2>&3
61		break;;
62	esac
63done  3>&2 2> $tmp/2 <<!
64foo
65!
66exit $((Errors))
67