2 # A suite of tests for bash word expansions
4 # This tests parameter and variable expansion, with an empahsis on
5 # proper quoting behavior.
10 # If you comment out the body of this function, you can do a diff against
11 # `expansion-tests.right' to see if the shell is behaving correctly
18 # Test the substitution quoting characters (CTLESC and CTLNUL) in different
34 # Test null strings without variable expansion
48 # Test the quirky behavior of $@ in ""
56 # Test null strings with variable expansion that fails
70 # Test null strings with variable expansion that succeeds
89 # Test the unquoted special quoting characters
103 # Test expansion of a variable that is unset
112 # Test empty string expansion
118 # Test command substitution with (disabled) history substitution
119 expect '<Hello World!>'
121 recho "`echo \"Hello world!\"`"
123 # Test some shell special characters
137 # This should give argv[1] = a argv[2] = b
139 FOO=`echo 'a b' | tr ' ' '\012'`
142 # This should give argv[1] = ^A argv[2] = ^B
144 FOO=`echo '
\ 1 \ 2' | tr ' ' '\012'`
147 # Test quoted and unquoted globbing characters
154 # Test patterns that come up when the shell quotes funny character
166 expect '< abc> <def> <ghi> <jkl >'
170 expect '<--abc> <def> <ghi> <jkl-->'
179 # Test combinations of different types of quoting in a fully-quoted string
180 # (so the WHOLLY_QUOTED tests fail and it doesn't get set)
181 expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>'
182 recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/"
184 # Test the various Posix parameter expansions
187 recho "${x:-$(echo "foo bar")}"
189 recho ${x:-$(echo "foo bar")}
205 # remove shortest trailing match
210 # remove longest trailing match
215 # remove shortest leading pattern
220 # remove longest leading pattern
225 # Command substitution and the quirky differences between `` and $()
236 # The difference between $* "$*" and "$@"
238 set "abc" "def ghi" "jkl"
240 expect '<abc> <def> <ghi> <jkl>'
243 expect '<abc def ghi jkl>'
249 # The special behavior of "$*", using the first character of $IFS as separator
250 expect '<abc:def ghi:jkl>'
255 expect '<abc> <def ghi> <jkl>'
258 expect '<xxabc> <def ghi> <jklyy>'
261 expect '<abc> <def ghi> <jklabc> <def ghi> <jkl>'
271 set $foo bar '' xyz "$foo" abc
273 expect '<bar> <> <xyz> <> <abc>'
276 # More tests of quoting and deferred evaluation
293 expect '<newline expected>'
295 *$NL*) recho "newline expected" ;;
300 *"?"*) recho "got it" ;;
305 *\?*) recho "got it" ;;
308 set one two three four five
309 expect '<one> <three> <five>'
310 recho $1 $3 ${5} $8 ${9}