--- /dev/null
+Test 0: var:ok
+File created:ok
+Test 1: var:ok
+File created:ok
+Test 2: var:ok
+File created:ok
+Test 3: var:ok
+File created:ok
+Test 4: var:ok
+File created:ok
+Test 5: var:ok
+File created:ok
--- /dev/null
+rm shell_test_$$ 2>/dev/null
+var=bad
+>shell_test_$$ var=ok
+echo "Test 0: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=bad
+var=ok >shell_test_$$
+echo "Test 1: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=ok
+true | var=bad >shell_test_$$
+echo "Test 2: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=bad
+{ var=ok >shell_test_$$; }
+echo "Test 3: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=ok
+{ var=bad >shell_test_$$; } &
+# cant use usleep as it isnt standard in $PATH --
+# we fail when testing busybox compiled solely as "hush"
+wait
+echo "Test 4: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=ok
+( var=bad >shell_test_$$ )
+echo "Test 5: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
--- /dev/null
+Ok: script fd is not closed
--- /dev/null
+# Builds a " 3>&- 4>&-" string.
+# Note: one of these fds is a directory opened to /proc/self/fd
+# for globbing. It is unwanted, but I don't know how to filter it out.
+find_fds() {
+ fds=""
+ for f in /proc/self/fd/*; do
+ test "$f" = "/proc/self/fd/0" && continue
+ test "$f" = "/proc/self/fd/1" && continue
+ test "$f" = "/proc/self/fd/2" && continue
+ fds="$fds ${f##*/}>&-"
+ done
+}
+
+find_fds
+fds1="$fds"
+
+# One of the fds is open to the script body
+# Close it while executing something.
+eval "find_fds $fds"
+
+# Shell should not lose that fd. Did it?
+find_fds
+test x"$fds1" = x"$fds" && { echo "Ok: script fd is not closed"; exit 0; }
+
+echo "Bug: script fd is closed"
+echo "fds1:$fds1"
+echo "fds2:$fds"
+exit 1
+
--- /dev/null
+z1.tmp: 1
+z2.tmp: 1
+"z1.tmp z2.tmp": TEST 0
--- /dev/null
+v='z1.tmp z2.tmp'
+echo TEST >$v
+echo 'z1.tmp:' `cat 'z1.tmp' 2>/dev/null; echo $?`
+echo 'z2.tmp:' `cat 'z2.tmp' 2>/dev/null; echo $?`
+echo '"z1.tmp z2.tmp":' `cat 'z1.tmp z2.tmp' 2>/dev/null; echo $?`
+rm z*.tmp
+++ /dev/null
-Test 0: var:ok
-File created:ok
-Test 1: var:ok
-File created:ok
-Test 2: var:ok
-File created:ok
-Test 3: var:ok
-File created:ok
-Test 4: var:ok
-File created:ok
-Test 5: var:ok
-File created:ok
+++ /dev/null
-rm shell_test_$$ 2>/dev/null
-var=bad
->shell_test_$$ var=ok
-echo "Test 0: var:$var"
-test -f shell_test_$$ && echo "File created:ok"
-
-rm shell_test_$$ 2>/dev/null
-var=bad
-var=ok >shell_test_$$
-echo "Test 1: var:$var"
-test -f shell_test_$$ && echo "File created:ok"
-
-rm shell_test_$$ 2>/dev/null
-var=ok
-true | var=bad >shell_test_$$
-echo "Test 2: var:$var"
-test -f shell_test_$$ && echo "File created:ok"
-
-rm shell_test_$$ 2>/dev/null
-var=bad
-{ var=ok >shell_test_$$; }
-echo "Test 3: var:$var"
-test -f shell_test_$$ && echo "File created:ok"
-
-rm shell_test_$$ 2>/dev/null
-var=ok
-{ var=bad >shell_test_$$; } &
-# cant use usleep as it isnt standard in $PATH --
-# we fail when testing busybox compiled solely as "hush"
-wait
-echo "Test 4: var:$var"
-test -f shell_test_$$ && echo "File created:ok"
-
-rm shell_test_$$ 2>/dev/null
-var=ok
-( var=bad >shell_test_$$ )
-echo "Test 5: var:$var"
-test -f shell_test_$$ && echo "File created:ok"
-
-rm shell_test_$$ 2>/dev/null
+++ /dev/null
-echo NOT SHOWN \2>/dev/null
-echo Ok
+++ /dev/null
-hush: can't open '/does/not/exist': No such file or directory
-One:1
-hush: can't open '/cant/be/created': No such file or directory
-One:1
-Ok
-hush: can't open '/cant/be/created': No such file or directory
-Zero:0
-hush: can't open '/cant/be/created': No such file or directory
-One:1
-hush: can't open '/cant/be/created': No such file or directory
-One:1
-hush: can't open '/cant/be/created': No such file or directory
-Zero:0
-Done
+++ /dev/null
-echo Error >/does/not/exist; echo One:$?
-t=BAD
-t=Ok >>/cant/be/created; echo One:$?
-echo $t
-! >/cant/be/created; echo Zero:$?
-exec >/cant/be/created; echo One:$?
-exec /bin/true >/cant/be/created; echo One:$?
-! exec /bin/true >/cant/be/created; echo Zero:$?
-echo Done
+++ /dev/null
-shell_test
-\shell_test
-\shell_test
-\shell_test
-Here1
-Ok1
-Here2
-Ok2
-Here3
-Ok3
-Here4
-Ok4
-Now with variable refs
-shell_test_1
-\shell_test_1
-\shell_test_1
-\shell_test_1
-Done
+++ /dev/null
-rm *shell_test* 2>/dev/null
-
->\shell_test
-echo *shell_test*
-rm *shell_test*
-
->\\shell_test
-echo *shell_test*
-rm *shell_test*
-
->"\shell_test"
-echo *shell_test*
-rm *shell_test*
-
->"\\shell_test"
-echo *shell_test*
-rm *shell_test*
-
-
-cat <<\shell_test
-Here1
-shell_test
-echo Ok1
-
-cat <<\\shell_test
-Here2
-\shell_test
-echo Ok2
-
-cat <<"\shell_test"
-Here3
-\shell_test
-echo Ok3
-
-cat <<"\\shell_test"
-Here4
-\shell_test
-echo Ok4
-
-
-echo Now with variable refs
-i=1
-
-
->\shell_test_$i
-echo *shell_test*
-rm *shell_test*
-
->\\shell_test_$i
-echo *shell_test*
-rm *shell_test*
-
->"\shell_test_$i"
-echo *shell_test*
-rm *shell_test*
-
->"\\shell_test_$i"
-echo *shell_test*
-rm *shell_test*
-
-echo Done;exit
-# UNFIXED BUG. bash apparently will expand $i even in terminating delimiter.
-# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
-# does not mandate this behavior.
-# This is not likely to be used much in real-world.
-
-cat <<\shell_test_$i
-Here1
-shell_test_$i
-echo Ok1
-
-cat <<\\shell_test_$i
-Here2
-\shell_test_$i
-echo Ok2
-
-cat <<"\shell_test_$i"
-Here3
-\shell_test_$i
-echo Ok3
-
-cat <<"\\shell_test_$i"
-Here4
-\shell_test_$i
-echo Ok4
+++ /dev/null
-Backgrounded pipes shall have their stdin redirected to /dev/null
-Zero:0
-Zero:0
-Done
+++ /dev/null
-echo "Backgrounded pipes shall have their stdin redirected to /dev/null"
-
-# 1. bash does not redirect stdin to /dev/null if it is interactive.
-# hush does it always (this is allowed by standards).
-
-# 2. Failure will result in this script hanging
-
-cat & wait; echo Zero:$?
-
-# This does not work for bash! bash bug?
-cat | cat & wait; echo Zero:$?
-
-echo Done
+++ /dev/null
-Testing multiple redirections to same fd
-Hello
-Done1
-Done2
+++ /dev/null
-echo "Testing multiple redirections to same fd"
-# bug was making us lose fd #1 after this:
-echo Hello >/dev/null 1>&2
-echo Done1
-echo Done2 >&2
+++ /dev/null
-Ok: script fd is not closed
+++ /dev/null
-# Builds a " 3>&- 4>&-" string.
-# Note: one of these fds is a directory opened to /proc/self/fd
-# for globbing. It is unwanted, but I don't know how to filter it out.
-find_fds() {
- fds=""
- for f in /proc/self/fd/*; do
- test "$f" = "/proc/self/fd/0" && continue
- test "$f" = "/proc/self/fd/1" && continue
- test "$f" = "/proc/self/fd/2" && continue
- fds="$fds ${f##*/}>&-"
- done
-}
-
-find_fds
-fds1="$fds"
-
-# One of the fds is open to the script body
-# Close it while executing something.
-eval "find_fds $fds"
-
-# Shell should not lose that fd. Did it?
-find_fds
-test x"$fds1" = x"$fds" && { echo "Ok: script fd is not closed"; exit 0; }
-
-echo "Bug: script fd is closed"
-echo "fds1:$fds1"
-echo "fds2:$fds"
-exit 1
-
+++ /dev/null
-z1.tmp: 1
-z2.tmp: 1
-"z1.tmp z2.tmp": TEST 0
+++ /dev/null
-v='z1.tmp z2.tmp'
-echo TEST >$v
-echo 'z1.tmp:' `cat 'z1.tmp' 2>/dev/null; echo $?`
-echo 'z2.tmp:' `cat 'z2.tmp' 2>/dev/null; echo $?`
-echo '"z1.tmp z2.tmp":' `cat 'z1.tmp z2.tmp' 2>/dev/null; echo $?`
-rm z*.tmp
--- /dev/null
+Test 0: var:ok
+File created:ok
+Test 1: var:ok
+File created:ok
+Test 2: var:ok
+File created:ok
+Test 3: var:ok
+File created:ok
+Test 4: var:ok
+File created:ok
+Test 5: var:ok
+File created:ok
--- /dev/null
+rm shell_test_$$ 2>/dev/null
+var=bad
+>shell_test_$$ var=ok
+echo "Test 0: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=bad
+var=ok >shell_test_$$
+echo "Test 1: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=ok
+true | var=bad >shell_test_$$
+echo "Test 2: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=bad
+{ var=ok >shell_test_$$; }
+echo "Test 3: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=ok
+{ var=bad >shell_test_$$; } &
+# cant use usleep as it isnt standard in $PATH --
+# we fail when testing busybox compiled solely as "hush"
+wait
+echo "Test 4: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
+var=ok
+( var=bad >shell_test_$$ )
+echo "Test 5: var:$var"
+test -f shell_test_$$ && echo "File created:ok"
+
+rm shell_test_$$ 2>/dev/null
--- /dev/null
+echo NOT SHOWN \2>/dev/null
+echo Ok
--- /dev/null
+hush: can't open '/does/not/exist': No such file or directory
+One:1
+hush: can't open '/cant/be/created': No such file or directory
+One:1
+Ok
+hush: can't open '/cant/be/created': No such file or directory
+Zero:0
+hush: can't open '/cant/be/created': No such file or directory
+One:1
+hush: can't open '/cant/be/created': No such file or directory
+One:1
+hush: can't open '/cant/be/created': No such file or directory
+Zero:0
+Done
--- /dev/null
+echo Error >/does/not/exist; echo One:$?
+t=BAD
+t=Ok >>/cant/be/created; echo One:$?
+echo $t
+! >/cant/be/created; echo Zero:$?
+exec >/cant/be/created; echo One:$?
+exec /bin/true >/cant/be/created; echo One:$?
+! exec /bin/true >/cant/be/created; echo Zero:$?
+echo Done
--- /dev/null
+shell_test
+\shell_test
+\shell_test
+\shell_test
+Here1
+Ok1
+Here2
+Ok2
+Here3
+Ok3
+Here4
+Ok4
+Now with variable refs
+shell_test_1
+\shell_test_1
+\shell_test_1
+\shell_test_1
+Done
--- /dev/null
+rm *shell_test* 2>/dev/null
+
+>\shell_test
+echo *shell_test*
+rm *shell_test*
+
+>\\shell_test
+echo *shell_test*
+rm *shell_test*
+
+>"\shell_test"
+echo *shell_test*
+rm *shell_test*
+
+>"\\shell_test"
+echo *shell_test*
+rm *shell_test*
+
+
+cat <<\shell_test
+Here1
+shell_test
+echo Ok1
+
+cat <<\\shell_test
+Here2
+\shell_test
+echo Ok2
+
+cat <<"\shell_test"
+Here3
+\shell_test
+echo Ok3
+
+cat <<"\\shell_test"
+Here4
+\shell_test
+echo Ok4
+
+
+echo Now with variable refs
+i=1
+
+
+>\shell_test_$i
+echo *shell_test*
+rm *shell_test*
+
+>\\shell_test_$i
+echo *shell_test*
+rm *shell_test*
+
+>"\shell_test_$i"
+echo *shell_test*
+rm *shell_test*
+
+>"\\shell_test_$i"
+echo *shell_test*
+rm *shell_test*
+
+echo Done;exit
+# UNFIXED BUG. bash apparently will expand $i even in terminating delimiter.
+# http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html
+# does not mandate this behavior.
+# This is not likely to be used much in real-world.
+
+cat <<\shell_test_$i
+Here1
+shell_test_$i
+echo Ok1
+
+cat <<\\shell_test_$i
+Here2
+\shell_test_$i
+echo Ok2
+
+cat <<"\shell_test_$i"
+Here3
+\shell_test_$i
+echo Ok3
+
+cat <<"\\shell_test_$i"
+Here4
+\shell_test_$i
+echo Ok4
--- /dev/null
+Backgrounded pipes shall have their stdin redirected to /dev/null
+Zero:0
+Zero:0
+Done
--- /dev/null
+echo "Backgrounded pipes shall have their stdin redirected to /dev/null"
+
+# 1. bash does not redirect stdin to /dev/null if it is interactive.
+# hush does it always (this is allowed by standards).
+
+# 2. Failure will result in this script hanging
+
+cat & wait; echo Zero:$?
+
+# This does not work for bash! bash bug?
+cat | cat & wait; echo Zero:$?
+
+echo Done
--- /dev/null
+Testing multiple redirections to same fd
+Hello
+Done1
+Done2
--- /dev/null
+echo "Testing multiple redirections to same fd"
+# bug was making us lose fd #1 after this:
+echo Hello >/dev/null 1>&2
+echo Done1
+echo Done2 >&2
--- /dev/null
+Ok
+Ok
+Done
--- /dev/null
+# Chars above 0x7f are used as special codes.
+# 0x81 is CTLESC (see ash.c).
+# The bug was that quoting and unquoting of them
+# was out of sync for redirect filenames.
+
+>unicode.sh
+printf 'echo Ok >uni\x81code\n' >>unicode.sh
+printf 'cat uni\x81code\n' >>unicode.sh
+printf 'cat uni?code\n' >>unicode.sh
+. ./unicode.sh
+rm uni*code*
+echo Done
--- /dev/null
+Ok
+Ok
+Done
--- /dev/null
+# Chars above 0x7f are used as special codes.
+# 0x81 is CTLESC (see ash.c).
+# The bug was that quoting and unquoting of them
+# was out of sync for redirect filenames.
+
+# Subcase when redirect filename is specified in a variable.
+
+>unicode.sh
+printf 'v=uni\x81code\n' >>unicode.sh
+printf 'echo Ok >"$v"\n' >>unicode.sh
+printf 'cat uni\x81code\n' >>unicode.sh
+printf 'cat uni?code\n' >>unicode.sh
+. ./unicode.sh
+rm uni*code*
+echo Done
--- /dev/null
+Ok
+Done:0
--- /dev/null
+echo Ok >file.tmp
+cat 0<>file.tmp
+echo Done:$?
+rm file.tmp
--- /dev/null
+tmp11
+tmp11
--- /dev/null
+x="tmp11:tmp22"
+
+# Bug was incorrectly expanding variables in >redir
+echo "${x%:*}" >"${x%:*}"
+echo tmp1*
+rm tmp1*
+
+# Also try unquoted
+echo "${x%:*}" >${x%:*}
+echo tmp1*
+rm tmp1*
--- /dev/null
+Ok: script fd is not closed
--- /dev/null
+# Builds a " 3>&- 4>&-" string.
+# Note: one of these fds is a directory opened to /proc/self/fd
+# for globbing. It is unwanted, but I don't know how to filter it out.
+find_fds() {
+ fds=""
+ for f in /proc/self/fd/*; do
+ test "$f" = "/proc/self/fd/0" && continue
+ test "$f" = "/proc/self/fd/1" && continue
+ test "$f" = "/proc/self/fd/2" && continue
+ fds="$fds ${f##*/}>&-"
+ done
+}
+
+find_fds
+fds1="$fds"
+
+# One of the fds is open to the script body
+# Close it while executing something.
+eval "find_fds $fds"
+
+# Shell should not lose that fd. Did it?
+find_fds
+test x"$fds1" = x"$fds" && { echo "Ok: script fd is not closed"; exit 0; }
+
+echo "Bug: script fd is closed"
+echo "fds1:$fds1"
+echo "fds2:$fds"
+exit 1
+
--- /dev/null
+z1.tmp: 1
+z2.tmp: 1
+"z1.tmp z2.tmp": TEST 0
--- /dev/null
+v='z1.tmp z2.tmp'
+echo TEST >$v
+echo 'z1.tmp:' `cat 'z1.tmp' 2>/dev/null; echo $?`
+echo 'z2.tmp:' `cat 'z2.tmp' 2>/dev/null; echo $?`
+echo '"z1.tmp z2.tmp":' `cat 'z1.tmp z2.tmp' 2>/dev/null; echo $?`
+rm z*.tmp