]> git.ipfire.org Git - thirdparty/bash.git/blame - tests/new-exp2.sub
bash-5.0 distribution sources and documentation
[thirdparty/bash.git] / tests / new-exp2.sub
CommitLineData
cce855bc
JA
1export LC_ALL=C
2export LANG=C
3
4# test out the new $(< filename) code
5# it should be exactly equivalent to $(cat filename)
6
d233b485 7FILENAME=$TMPDIR/bashtmp.x$$
cce855bc
JA
8
9trap 'rm -f $FILENAME' 0
10
11cat >$FILENAME << EOF
12line 1
13line 2
14line 3
15EOF
16
17LINES1=$(cat $FILENAME)
18LINES2=$(< $FILENAME)
19
20if [[ $LINES1 != $LINES2 ]]; then
21 echo 'whoops: $(< filename) failed'
22fi
23
d233b485 24LINES2=$(< $TMPDIR/bashtmp.x*)
cce855bc
JA
25if [[ $LINES1 != $LINES2 ]]; then
26 echo 'whoops: $(< filename) with glob expansion failed'
27fi
28
29# but the glob expansion in the redirection should fail in posix mode
30set -o posix
d233b485
CR
31exec 3>&2
32exec 2>/dev/null
33LINES2=$(< $TMPDIR/bashtmp.x*)
34exec 2>&3
35if [[ $LINES2 -gt 0 ]]; then
36 echo "whoops: redirection glob expansion should be disabled in posix mode" >&2
37fi
cce855bc
JA
38set +o posix
39
40# now see what happens when we try it with a non-existant file
d233b485 41rm -f /tmp/redir-notthere
cce855bc
JA
42LINES3=$(< /tmp/redir-notthere)
43echo $?
ac50fbac
CR
44
45# These were bugs through bash-4.2
46{ : "$({xxxxxxxxxxxxxxxxxxxx}</dev/stdin)"; } <<<'hi'
47echo ${xxxxxxxxxxxxxxxxxxxx}
48
49{ echo "$(1111111111111111111111</dev/stdin)"; } <<<'hi'