Patch from David Meggy to make the swap default to the new version if no
[oweals/busybox.git] / tests / sh.testcases
1 # try running this with bash, ksh, ash, and hush.
2
3 # simple quoting rules.
4 echo a  b
5 echo "a  b"
6 echo a "" b
7 echo a '' b
8 echo hello?
9 echo "hello?"
10 echo t* hello
11 echo t\* hello
12
13 # quick and painless exit for lash
14 if false; then true; exit; fi
15
16 # fairly simple command substitution
17 echo `echo -e foo\\\necho bar`
18
19 echo THIS IS A TEST >foo
20 cat $(echo FOO | tr 'A-Z' 'a-z')
21 cat foo | tr 'A-Z' 'a-z'
22 cat $(echo FOO | tr 'A-Z' 'a-z') | tr 'A-Z' 'a-z'
23
24 cat foo | if true;  then tr 'A-Z' 'a-z'; else echo bar1; fi
25 cat foo | if false; then tr 'A-Z' 'a-z'; else echo bar2; fi
26 if true;  then tr 'A-Z' 'a-z'; else echo bar3; fi <foo
27 if false; then tr 'A-Z' 'a-z'; else echo bar4; fi <foo
28 if true || false; then echo foo; else echo bar5; fi
29 if true && false; then echo bar6; else echo foo; fi
30
31 # basic distinction between local and env variables
32 unset FOO
33 FOO=bar env | grep FOO
34 echo "but not here: $FOO"
35 FOO=bar
36 env | grep FOO
37 echo "yes, here: $FOO"
38 FOO=
39 echo a $FOO b
40 echo "a $FOO b"
41
42 # not quite so basic variables.  Credit to Matt Kraai.
43 unset FOO
44 FOO=bar
45 export FOO
46 env | grep FOO
47 unset FOO
48 export FOO=bar
49 FOO=baz
50 env | grep FOO
51
52 # interaction between environment variables and if/then and subshells
53 FOO=default
54 if true; then FOO=new; fi
55 echo $FOO
56 FOO=default
57 (FOO=bogus)
58 echo $FOO
59
60 # make sure we can duplicate file descriptors properly
61 echo replacement >foo 2>&1
62 cat foo
63 cat doesnt_exist >foo 2>&1
64 tr 'a-z' 'A-Z' <foo
65
66 # fairly simple example of hush expanding variables too early
67 unset TMP
68 rm -f fish
69 TMP=fish && >$TMP
70 ls fish
71
72 # ash, lash, and hush do not create wish; bash and ksh do.
73 # Thanks to Tapani Tarvainen <tt@mit.jyu.fi> for this stress test.
74 unset TMP
75 rm -f wish
76 TMP=wish >$TMP
77 ls wish
78
79 # The following example shows that hush's parser is
80 # not _really_ Bourne compatible
81 echo "echo Hello World" >"a=b"
82 unset a
83 chmod a+x "a=b"
84 PATH=$PATH:.
85 "a=b"
86 echo $a
87
88 # assuming the shell wasn't too buggy, clean up the mess
89 rm -f a=b wish fish foo