| 1 | #!/bin/bash | 
| 2 | # | 
| 3 | # Tests for quotes. | 
| 4 | |
| 5 | ### Unquoted words | 
| 6 | echo unquoted words | 
| 7 | # stdout: unquoted words | 
| 8 | |
| 9 | ### Single-quoted | 
| 10 | echo 'single quoted' | 
| 11 | # stdout: single quoted | 
| 12 | |
| 13 | ### Two single-quoted parts | 
| 14 | echo 'two single-quoted pa''rts in one token' | 
| 15 | # stdout: two single-quoted parts in one token | 
| 16 | |
| 17 | ### Unquoted and single quoted | 
| 18 | echo unquoted' and single-quoted' | 
| 19 | # stdout: unquoted and single-quoted | 
| 20 | |
| 21 | ### newline inside single-quoted string | 
| 22 | echo 'newline | 
| 23 | inside single-quoted string' | 
| 24 | # stdout-json: "newline\ninside single-quoted string\n" | 
| 25 | |
| 26 | ### Double-quoted | 
| 27 | echo "double quoted" | 
| 28 | # stdout: double quoted | 
| 29 | |
| 30 | ### Mix of quotes in one word | 
| 31 | echo unquoted' single-quoted'" double-quoted "unquoted | 
| 32 | # stdout: unquoted single-quoted double-quoted unquoted | 
| 33 | |
| 34 | ### Var substitution | 
| 35 | FOO=bar | 
| 36 | echo "==$FOO==" | 
| 37 | # stdout: ==bar== | 
| 38 | |
| 39 | ### Var substitution with braces | 
| 40 | FOO=bar | 
| 41 | echo foo${FOO} | 
| 42 | # stdout: foobar | 
| 43 | |
| 44 | ### Var substitution with braces, quoted | 
| 45 | FOO=bar | 
| 46 | echo "foo${FOO}" | 
| 47 | # stdout: foobar | 
| 48 | |
| 49 | ### Var length | 
| 50 | FOO=bar | 
| 51 | echo "foo${#FOO}" | 
| 52 | # stdout: foo3 | 
| 53 | |
| 54 | ### Backslash escapes | 
| 55 | echo \$ \| \a \b \c \d \\ | 
| 56 | # stdout: $ | a b c d \ | 
| 57 | |
| 58 | ### Backslash escapes inside double quoted string | 
| 59 | echo "\$ \\ \\ \p \q" | 
| 60 | # stdout: $ \ \ \p \q | 
| 61 | |
| 62 | ### C-style backslash escapes inside double quoted string | 
| 63 | # mksh and dash implement POSIX incompatible extensions. $ ` " \ <newline> | 
| 64 | # are the only special ones | 
| 65 | echo "\a \b" | 
| 66 | # stdout: \a \b | 
| 67 | # BUG dash/mksh stdout-json: "\u0007 \u0008\n" | 
| 68 | |
| 69 | # BUG | 
| 70 | |
| 71 | ### Literal $ | 
| 72 | echo $ | 
| 73 | # stdout: $ | 
| 74 | |
| 75 | ### Quoted Literal $ | 
| 76 | echo $ "$" $ | 
| 77 | # stdout: $ $ $ | 
| 78 | |
| 79 | ### Line continuation | 
| 80 | echo foo\ | 
| 81 | $ | 
| 82 | # stdout: foo$ | 
| 83 | |
| 84 | ### $? split over multiple lines | 
| 85 | # Same with $$, etc. OSH won't do this because $? is a single token. | 
| 86 | echo $\ | 
| 87 | ? | 
| 88 | # stdout: $? | 
| 89 | # OK bash/mksh stdout: 0 | 
| 90 | |
| 91 | # | 
| 92 | # Bad quotes | 
| 93 | # | 
| 94 | |
| 95 | # TODO: Also test unterminated quotes inside ${} and $() | 
| 96 | |
| 97 | ### Unterminated single quote | 
| 98 | # code: ls foo bar ' | 
| 99 | # status: 2 | 
| 100 | # OK mksh status: 1 | 
| 101 | |
| 102 | ### Unterminated double quote | 
| 103 | # code: ls foo bar " | 
| 104 | # status: 2 | 
| 105 | # OK mksh status: 1 | 
| 106 | |
| 107 | |
| 108 | # | 
| 109 | # TODO: Might be another section? | 
| 110 | # | 
| 111 | |
| 112 | ### Semicolon | 
| 113 | echo separated; echo by semi-colon | 
| 114 | # stdout-json: "separated\nby semi-colon\n" | 
| 115 | |
| 116 | # | 
| 117 | # TODO: Variable substitution operators. | 
| 118 | # | 
| 119 | |
| 120 | ### No tab escapes within single quotes | 
| 121 | # dash and mksh allow this, which is a BUG. | 
| 122 | # POSIX says: "Enclosing characters in single-quotes ( '' ) shall preserve the | 
| 123 | # literal value of each character within the single-quotes. A single-quote | 
| 124 | # cannot occur within single-quotes" | 
| 125 | echo 'a\tb' | 
| 126 | # stdout: a\tb | 
| 127 | # BUG dash/mksh stdout-json: "a\tb\n" | 
| 128 | |
| 129 | # See if it supports ANSI C escapes. Bash supports this, but dash does NOT. I | 
| 130 | # guess dash you would do IFS=$(printf '\n\t') | 
| 131 | |
| 132 | ### $'' | 
| 133 | echo $'foo' | 
| 134 | # stdout: foo | 
| 135 | # N-I dash stdout: $foo | 
| 136 | |
| 137 | ### $'' with newlines | 
| 138 | echo $'col1\ncol2\ncol3' | 
| 139 | # stdout-json: "col1\ncol2\ncol3\n" | 
| 140 | # In dash, \n is special within single quotes | 
| 141 | # N-I dash stdout-json: "$col1\ncol2\ncol3\n" | 
| 142 | |
| 143 | ### $"" | 
| 144 | echo $"foo" | 
| 145 | # stdout: foo | 
| 146 | # N-I dash stdout: $foo | 
| 147 | |
| 148 | ### printf | 
| 149 | # This accepts \t by itself, hm. | 
| 150 | printf "c1\tc2\nc3\tc4\n" | 
| 151 | # stdout-json: "c1\tc2\nc3\tc4\n" |