| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Tests that explore parsing corner cases. |
| 4 | |
| 5 | |
| 6 | ### Bad env name: hyphen |
| 7 | # bash and dash disagree on exit code. |
| 8 | export FOO-BAR=foo |
| 9 | # status: 2 |
| 10 | # OK bash/mksh status: 1 |
| 11 | |
| 12 | ### Bad env name: period |
| 13 | export FOO.BAR=foo |
| 14 | # status: 2 |
| 15 | # OK bash/mksh status: 1 |
| 16 | |
| 17 | ### Bad var sub |
| 18 | echo $% |
| 19 | # stdout: $% |
| 20 | |
| 21 | ### Bad braced var sub -- not allowed |
| 22 | echo ${%} |
| 23 | # status: 2 |
| 24 | # OK bash/mksh status: 1 |
| 25 | |
| 26 | ### Bad var sub caught at parse time |
| 27 | if test -f /; then |
| 28 | echo ${%} |
| 29 | else |
| 30 | echo ok |
| 31 | fi |
| 32 | # status: 2 |
| 33 | # BUG dash/bash/mksh status: 0 |
| 34 | |
| 35 | ### Pipe with while |
| 36 | seq 3 | while read i |
| 37 | do |
| 38 | echo ".$i" |
| 39 | done |
| 40 | # stdout-json: ".1\n.2\n.3\n" |
| 41 | |
| 42 | ### Length of length of ARGS! |
| 43 | func() { echo ${##}; }; func 0 1 2 3 4 5 6 7 8 |
| 44 | # stdout: 1 |
| 45 | |
| 46 | ### Length of length of ARGS! 2 digit |
| 47 | func() { echo ${##}; }; func 0 1 2 3 4 5 6 7 8 9 |
| 48 | # stdout: 2 |
| 49 | |
| 50 | ### $1 .. $9 are scoped, while $0 is not |
| 51 | func() { echo $0 $1 $2 | sed -e 's/.*sh/sh/'; }; func a b |
| 52 | # stdout: sh a b |
| 53 | |
| 54 | ### Chained && and || -- || has higher precedence? |
| 55 | # It looks like expr 2 || expr 3 is evaluated at once. |
| 56 | expr 1 && expr 2 || expr 3 && expr 4; echo "result $?" |
| 57 | # stdout-json "1\n2\n4\nresult 0\n" |
| 58 | |
| 59 | ### Pipeline comments |
| 60 | echo abcd | # input |
| 61 | # blank line |
| 62 | tr a-z A-Z # transform |
| 63 | # stdout: ABCD |
| 64 | |
| 65 | ### Command block |
| 66 | { which ls; } |
| 67 | # stdout: /bin/ls |
| 68 | |
| 69 | ### { is its own word, needs a space |
| 70 | # dash gives 127; bash gives 2 |
| 71 | {ls; } |
| 72 | # parse time error because of } |
| 73 | # status: 2 |
| 74 | # runtime error |
| 75 | # OK mksh status: 1 |
| 76 | # command not found for dash |
| 77 | # OK dash status: 127 |
| 78 | |
| 79 | |
| 80 | |
| 81 | |
| 82 |