Mark Whitley | 04052f9 | 2001-05-24 17:15:33 +0000 | [diff] [blame] | 1 | # try running this with bash, ksh, ash, and hush. |
Mark Whitley | 4f6aea8 | 2001-05-24 23:05:13 +0000 | [diff] [blame] | 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 |
Mark Whitley | 04052f9 | 2001-05-24 17:15:33 +0000 | [diff] [blame] | 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 | |
Eric Andersen | 04407e5 | 2001-06-07 16:42:05 +0000 | [diff] [blame] | 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 | |
Matt Kraai | 12422ff | 2001-06-05 17:48:47 +0000 | [diff] [blame] | 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 | |
Mark Whitley | 4f6aea8 | 2001-05-24 23:05:13 +0000 | [diff] [blame] | 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 | |
Eric Andersen | 431a184 | 2002-10-18 22:18:10 +0000 | [diff] [blame] | 72 | # ash, lash, and hush do not create wish; bash and ksh do. |
Mark Whitley | 04052f9 | 2001-05-24 17:15:33 +0000 | [diff] [blame] | 73 | # Thanks to Tapani Tarvainen <tt@mit.jyu.fi> for this stress test. |
| 74 | unset TMP |
Eric Andersen | 431a184 | 2002-10-18 22:18:10 +0000 | [diff] [blame] | 75 | rm -f wish |
| 76 | TMP=wish >$TMP |
| 77 | ls wish |
Mark Whitley | 04052f9 | 2001-05-24 17:15:33 +0000 | [diff] [blame] | 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 |
Eric Andersen | 431a184 | 2002-10-18 22:18:10 +0000 | [diff] [blame] | 89 | rm -f a=b wish fish foo |