1 | ## oils_failures_allowed: 0
|
2 |
|
3 | #### Conflict with extglob @( can be avoided with ,(
|
4 |
|
5 | shopt -s extglob
|
6 |
|
7 | [[ foo.py == @(*.sh|*.py) ]]
|
8 | echo status=$?
|
9 |
|
10 | # Synonym. This is a syntax error in bash.
|
11 | [[ foo.py == ,(*.sh|*.py) ]]
|
12 | echo status=$?
|
13 |
|
14 | ## STDOUT:
|
15 | status=0
|
16 | status=0
|
17 | ## END
|
18 |
|
19 | #### split command sub @() in expression mode
|
20 | shopt --set parse_proc parse_at
|
21 |
|
22 | var x = @(seq 3)
|
23 |
|
24 | write -- @x
|
25 | ## STDOUT:
|
26 | 1
|
27 | 2
|
28 | 3
|
29 | ## END
|
30 |
|
31 | #### split command sub @() in command mode
|
32 |
|
33 | shopt -s parse_at
|
34 | write -- @(seq 3)
|
35 |
|
36 | echo --
|
37 | IFS=x
|
38 | x=axbxxc
|
39 | argv.py $x
|
40 |
|
41 | # This construct behaves the same with simple_word_eval on
|
42 | # Not affected by IFS
|
43 | echo --
|
44 | shopt -s simple_word_eval
|
45 | write -- @(seq 3)
|
46 |
|
47 | echo --
|
48 | argv.py @(echo $x)
|
49 |
|
50 | ## STDOUT:
|
51 | 1
|
52 | 2
|
53 | 3
|
54 | --
|
55 | ['a', 'b', '', 'c']
|
56 | --
|
57 | 1
|
58 | 2
|
59 | 3
|
60 | --
|
61 | ['axbxxc']
|
62 | ## END
|
63 |
|
64 | #### @() decodes J8 Lines
|
65 |
|
66 | # syntax errors - TODO: document this in doc/chap-errors
|
67 |
|
68 | # - syntax error in J8 string (bad escape, no closing quote)
|
69 | # - extra text after line
|
70 | # - unquoted line isn't valid UTF-8
|
71 |
|
72 | var b = @(
|
73 | # unquoted: spaces stripped at beginning and end
|
74 | echo ' unquoted "" word '
|
75 |
|
76 | # empty line is ignored
|
77 | echo
|
78 |
|
79 | # Not allowed, since unquoted lines should be UTF-8
|
80 | #echo $'binary \xff';
|
81 |
|
82 | echo ' " json \u03bc " '
|
83 | echo ' j" json j prefix \u03bc " '
|
84 | echo " u' j8 u \\u{3bc} ' "
|
85 | echo " b' j8 b \\u{3bc} ' "
|
86 |
|
87 | # no prefix is like u''
|
88 | echo " ' j8 no prefix \\u{3bc} ' "
|
89 | )
|
90 |
|
91 | json write (b)
|
92 |
|
93 | ## STDOUT:
|
94 | [
|
95 | "unquoted \"\" word",
|
96 | " json μ ",
|
97 | " json j prefix μ ",
|
98 | " j8 u μ ",
|
99 | " j8 b μ ",
|
100 | " j8 no prefix μ "
|
101 | ]
|
102 | ## END
|
103 |
|
104 | #### for loop using @(seq $n)
|
105 | shopt -s oil:upgrade
|
106 |
|
107 | for x in @(seq 3) {
|
108 | echo "[$x]"
|
109 | }
|
110 | for x in @(seq 3) {
|
111 | argv.py z @[glob("[$x]")]
|
112 | }
|
113 | ## STDOUT:
|
114 | [1]
|
115 | [2]
|
116 | [3]
|
117 | ['z']
|
118 | ['z']
|
119 | ['z']
|
120 | ## END
|
121 |
|
122 | #### @() can't start in the middle of the word
|
123 | shopt -s extglob # this makes it match in bash
|
124 | shopt -s oil:upgrade
|
125 |
|
126 | # This is currently a RUNTIME error when simple_word_eval is on
|
127 |
|
128 | touch foo.py
|
129 | echo f@(*.py)
|
130 | ## status: 1
|
131 | ## STDOUT:
|
132 | ## END
|
133 | ## OK bash status: 0
|
134 | ## OK bash STDOUT:
|
135 | foo.py
|
136 | ## END
|
137 |
|
138 | #### @() can't have any tokens after it
|
139 | shopt -s oil:upgrade
|
140 |
|
141 | write -- @(seq 2)
|
142 | write -- @(seq 3)x
|
143 | ## status: 2
|
144 | ## STDOUT:
|
145 | 1
|
146 | 2
|
147 | ## END
|