1 |
# @( conflict |
2 |
|
3 |
#### extglob |
4 |
shopt -s extglob |
5 |
|
6 |
[[ foo.py == @(*.sh|*.py) ]] |
7 |
echo status=$? |
8 |
|
9 |
# Synonym. This is a syntax error in bash. |
10 |
[[ foo.py == ,(*.sh|*.py) ]] |
11 |
echo status=$? |
12 |
|
13 |
## STDOUT: |
14 |
status=0 |
15 |
status=0 |
16 |
## END |
17 |
|
18 |
#### split command sub @() in expression mode |
19 |
var x = @(seq 3) |
20 |
|
21 |
shopt -s parse_at |
22 |
write -- @x |
23 |
## STDOUT: |
24 |
1 |
25 |
2 |
26 |
3 |
27 |
## END |
28 |
|
29 |
#### split command sub @() in command mode |
30 |
|
31 |
shopt -s parse_at |
32 |
write -- @(seq 3) |
33 |
|
34 |
echo -- |
35 |
IFS=x |
36 |
x=axbxxc |
37 |
argv.py $x |
38 |
|
39 |
# This construct behaves the same with simple_word_eval on |
40 |
echo -- |
41 |
shopt -s simple_word_eval |
42 |
write -- @(seq 3) |
43 |
|
44 |
|
45 |
echo -- |
46 |
write -- @(echo axbxxc) |
47 |
|
48 |
## STDOUT: |
49 |
1 |
50 |
2 |
51 |
3 |
52 |
-- |
53 |
['a', 'b', '', 'c'] |
54 |
-- |
55 |
1 |
56 |
2 |
57 |
3 |
58 |
-- |
59 |
a |
60 |
b |
61 |
|
62 |
c |
63 |
## END |
64 |
|
65 |
#### Idiomatic for loop using @(seq $n) |
66 |
shopt -s oil:basic |
67 |
|
68 |
for x in @(seq 3) { |
69 |
echo "[$x]" |
70 |
} |
71 |
for x in @(seq 3) { |
72 |
argv.py z [$x] # note this is an empty glob!!! |
73 |
} |
74 |
## STDOUT: |
75 |
[1] |
76 |
[2] |
77 |
[3] |
78 |
['z'] |
79 |
['z'] |
80 |
['z'] |
81 |
## END |
82 |
|
83 |
#### @() can't start in the middle of the word |
84 |
|
85 |
# TODO: This could be as syntax error? We need filename globbing to match |
86 |
# bash. |
87 |
|
88 |
shopt -s extglob # this makes it match in bash |
89 |
shopt -s oil:basic |
90 |
|
91 |
touch foo.py |
92 |
echo f@(*.py) |
93 |
## STDOUT: |
94 |
f@(*.py) |
95 |
## END |
96 |
## OK bash STDOUT: |
97 |
foo.py |
98 |
## END |
99 |
|
100 |
#### @() can't have any tokens after it |
101 |
shopt -s oil:basic |
102 |
|
103 |
write -- @(seq 2) |
104 |
write -- @(seq 3)x |
105 |
## status: 2 |
106 |
## STDOUT: |
107 |
1 |
108 |
2 |
109 |
## END |