| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | ### Bad var sub |
| 4 | echo $% |
| 5 | # stdout: $% |
| 6 | |
| 7 | ### Bad braced var sub -- not allowed |
| 8 | echo ${%} |
| 9 | # status: 2 |
| 10 | # OK bash/mksh status: 1 |
| 11 | |
| 12 | ### Bad var sub caught at parse time |
| 13 | if test -f /; then |
| 14 | echo ${%} |
| 15 | else |
| 16 | echo ok |
| 17 | fi |
| 18 | # status: 2 |
| 19 | # BUG dash/bash/mksh status: 0 |
| 20 | |
| 21 | ### Incomplete while |
| 22 | echo hi; while |
| 23 | echo status=$? |
| 24 | # status: 2 |
| 25 | # stdout-json: "" |
| 26 | # OK mksh status: 1 |
| 27 | |
| 28 | ### Incomplete for |
| 29 | echo hi; for |
| 30 | echo status=$? |
| 31 | # status: 2 |
| 32 | # stdout-json: "" |
| 33 | # OK mksh status: 1 |
| 34 | |
| 35 | ### Incomplete if |
| 36 | echo hi; if |
| 37 | echo status=$? |
| 38 | # status: 2 |
| 39 | # stdout-json: "" |
| 40 | # OK mksh status: 1 |
| 41 | |
| 42 | ### do unexpected |
| 43 | do echo hi |
| 44 | # status: 2 |
| 45 | # stdout-json: "" |
| 46 | # OK mksh status: 1 |
| 47 | |
| 48 | ### } is a parse error |
| 49 | } |
| 50 | echo should not get here |
| 51 | # stdout-json: "" |
| 52 | # status: 2 |
| 53 | # OK mksh status: 1 |
| 54 | |
| 55 | ### { is its own word, needs a space |
| 56 | # bash and mksh give parse time error because of } |
| 57 | # dash gives 127 as runtime error |
| 58 | {ls; } |
| 59 | echo "status=$?" |
| 60 | # stdout-json: "" |
| 61 | # status: 2 |
| 62 | # OK mksh status: 1 |
| 63 | # BUG dash stdout: status=127 |
| 64 | # BUG dash status: 0 |
| 65 | |
| 66 | ### } on the second line |
| 67 | set -o errexit |
| 68 | {ls; |
| 69 | } |
| 70 | # status: 127 |
| 71 | |
| 72 | ### Invalid for loop variable name |
| 73 | for i.j in a b c; do |
| 74 | echo hi |
| 75 | done |
| 76 | echo done |
| 77 | # stdout-json: "" |
| 78 | # status: 2 |
| 79 | # OK mksh status: 1 |
| 80 | # OK bash status: 0 |
| 81 | # BUG bash stdout: done |
| 82 | |
| 83 | ### bad var name globally isn't parsed like an assignment |
| 84 | # bash and dash disagree on exit code. |
| 85 | FOO-BAR=foo |
| 86 | # status: 127 |
| 87 | |
| 88 | ### bad var name in export |
| 89 | # bash and dash disagree on exit code. |
| 90 | export FOO-BAR=foo |
| 91 | # status: 2 |
| 92 | # OK bash/mksh status: 1 |
| 93 | |
| 94 | ### bad var name in local |
| 95 | # bash and dash disagree on exit code. |
| 96 | f() { |
| 97 | local FOO-BAR=foo |
| 98 | } |
| 99 | # status: 2 |
| 100 | # BUG dash/bash/mksh status: 0 |