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
167 expect '< abc> <def> <ghi> <jkl >'
169 expect '< abc> <def> <ghi> <jkl >'
173 expect '<--abc> <def> <ghi> <jkl-->'
177 expect '<a b> <cd> <ef> <gh>'
179 expect '<a b> <cd> <ef> <gh>'
181 expect '<a b> <cd> <ef> <gh>'
189 # Test combinations of different types of quoting in a fully-quoted string
190 # (so the WHOLLY_QUOTED tests fail and it doesn't get set)
191 expect '</^root:/{s/^[^:]*:[^:]*:\([^:]*\).*$/\1/>'
192 recho "/^root:/{s/^[^:]*:[^:]*:\([^:]*\).*"'$'"/\1/"
194 # Test the various Posix parameter expansions
197 recho "${x:-$(echo "foo bar")}"
199 recho ${x:-$(echo "foo bar")}
215 # remove shortest trailing match
220 # remove longest trailing match
225 # remove shortest leading pattern
230 # remove longest leading pattern
235 # Command substitution and the quirky differences between `` and $()
246 # The difference between $* "$*" and "$@"
248 set "abc" "def ghi" "jkl"
250 expect '<abc> <def> <ghi> <jkl>'
253 expect '<abc def ghi jkl>'
259 # The special behavior of "$*", using the first character of $IFS as separator
260 expect '<abc:def ghi:jkl>'
265 expect '<abc> <def ghi> <jkl>'
268 expect '<xxabc> <def ghi> <jklyy>'
271 expect '<abc> <def ghi> <jklabc> <def ghi> <jkl>'
281 set $foo bar '' xyz "$foo" abc
283 expect '<bar> <> <xyz> <> <abc>'
286 # More tests of quoting and deferred evaluation
303 expect '<newline expected>'
305 *$NL*) recho "newline expected" ;;
310 *"?"*) recho "got it" ;;
315 *\?*) recho "got it" ;;
318 set one two three four five
319 expect '<one> <three> <five>'
320 recho $1 $3 ${5} $8 ${9}
338 # test word splitting of assignment statements not preceding a command
341 expect '<a> <b> <c> <d> <e>'