| 1 | #!/bin/bash |
| 2 | |
| 3 | ### no expansion |
| 4 | echo {foo} |
| 5 | # stdout: {foo} |
| 6 | |
| 7 | ### expansion |
| 8 | echo {foo,bar} |
| 9 | # stdout: foo bar |
| 10 | |
| 11 | ### double expansion |
| 12 | echo {a,b}_{c,d} |
| 13 | # stdout: a_c a_d b_c b_d |
| 14 | |
| 15 | ### { in expansion |
| 16 | # bash and mksh treat this differently. bash treats the |
| 17 | # first { is a prefix. I think it's harder to read, and \{{a,b} should be |
| 18 | # required. |
| 19 | echo {{a,b} |
| 20 | # stdout: {{a,b} |
| 21 | # BUG bash stdout: {a {b |
| 22 | |
| 23 | ### quoted { in expansion |
| 24 | echo \{{a,b} |
| 25 | # stdout: {a {b |
| 26 | |
| 27 | ### } in expansion |
| 28 | # hm they treat this the SAME. Leftmost { is matched by first }, and then |
| 29 | # there is another } as the postfix. |
| 30 | echo {a,b}} |
| 31 | # stdout: a} b} |
| 32 | |
| 33 | ### Empty expansion |
| 34 | echo a{X,,Y}b |
| 35 | # stdout: aXb ab aYb |
| 36 | |
| 37 | ### nested brace expansion |
| 38 | echo X{A,x{a,b}y,B}Y |
| 39 | # stdout: XAY XxayY XxbyY XBY |
| 40 | |
| 41 | ### expansion on RHS of assignment |
| 42 | # I think bash's behavior is more consistent. No splitting either. |
| 43 | v={X,Y} |
| 44 | echo $v |
| 45 | # stdout: {X,Y} |
| 46 | # BUG mksh stdout: X Y |
| 47 | |
| 48 | ### no expansion with RHS assignment |
| 49 | {v,x}=X |
| 50 | # status: 127 |
| 51 | |
| 52 | ### Tilde expansion |
| 53 | HOME=/home/foo |
| 54 | echo ~ |
| 55 | HOME=/home/bar |
| 56 | echo ~ |
| 57 | # stdout-json: "/home/foo\n/home/bar\n" |
| 58 | |
| 59 | ### Tilde expansion with brace expansion |
| 60 | # The brace expansion happens FIRST. After that, the second token has tilde |
| 61 | # FIRST, so it gets expanded. The first token has an unexpanded tilde, because |
| 62 | # it's not in the leading position. |
| 63 | # NOTE: mksh gives different behavior! So it probably doesn't matter that |
| 64 | # much... |
| 65 | HOME=/home/bob |
| 66 | echo {foo~,~}/bar |
| 67 | # stdout: foo~/bar /home/bob/bar |
| 68 | # OK mksh stdout: foo~/bar ~/bar |
| 69 | |
| 70 | ### Two kinds of tilde expansion |
| 71 | # ~/foo and ~bar |
| 72 | HOME=/home/bob |
| 73 | echo ~{/src,root} |
| 74 | # stdout: /home/bob/src /root |
| 75 | # OK mksh stdout: ~/src ~root |
| 76 | |
| 77 | ### Tilde expansion come before var expansion |
| 78 | HOME=/home/bob |
| 79 | foo=~ |
| 80 | echo $foo |
| 81 | foo='~' |
| 82 | echo $foo |
| 83 | # In the second instance, we expand into a literal ~, and since var expansion |
| 84 | # comes after tilde expansion, it is NOT tried again. |
| 85 | # stdout-json: "/home/bob\n~\n" |