xref: /titanic_41/usr/src/lib/libshell/common/tests/select.sh (revision 4a7ceb24cfcc0a97f96d86cfe5852ae445b50e57)
1########################################################################
2#                                                                      #
3#               This software is part of the ast package               #
4#           Copyright (c) 1982-2007 AT&T Knowledge Ventures            #
5#                      and is licensed under the                       #
6#                  Common Public License, Version 1.0                  #
7#                      by AT&T Knowledge Ventures                      #
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
30trap "rm -f /tmp/Sh$$*" EXIT
31PS3='ABC '
32
33cat > /tmp/Sh$$.1 <<\!
341) foo
352) bar
363) bam
37!
38
39select i in foo bar bam
40do	case $i in
41	foo)	break;;
42	*)	err_exit "select 1 not working"
43		break;;
44	esac
45done 2> /dev/null <<!
461
47!
48
49unset i
50select i in foo bar bam
51do	case $i in
52	foo)	err_exit "select foo not working" 2>&3
53		break;;
54	*)	if	[[ $REPLY != foo ]]
55		then	err_exit "select REPLY not correct" 2>&3
56		fi
57		( set -u; : $i ) || err_exit "select: i not set to null" 2>&3
58		break;;
59	esac
60done  3>&2 2> /tmp/Sh$$.2 <<!
61foo
62!
63exit $((Errors))
64