OILS / spec / ysh-command-sub.test.sh View on Github | oilshell.org

126 lines, 68 significant
1## oils_failures_allowed: 1
2
3#### Conflict with extglob @( can be avoided with ,(
4
5shopt -s extglob
6
7[[ foo.py == @(*.sh|*.py) ]]
8echo status=$?
9
10# Synonym. This is a syntax error in bash.
11[[ foo.py == ,(*.sh|*.py) ]]
12echo status=$?
13
14## STDOUT:
15status=0
16status=0
17## END
18
19#### split command sub @() in expression mode
20shopt --set parse_proc parse_at
21
22var x = @(seq 3)
23
24write -- @x
25## STDOUT:
261
272
283
29## END
30
31#### split command sub @() in command mode
32
33shopt -s parse_at
34write -- @(seq 3)
35
36echo --
37IFS=x
38x=axbxxc
39argv.py $x
40
41# This construct behaves the same with simple_word_eval on
42echo --
43shopt -s simple_word_eval
44write -- @(seq 3)
45
46
47echo --
48write -- @(echo axbxxc)
49
50## STDOUT:
511
522
533
54--
55['a', 'b', '', 'c']
56--
571
582
593
60--
61a
62b
63
64c
65## END
66
67#### @() decodes J8 Lines
68
69var b = @(
70 echo " unquoted ";
71 # I guess this is allowed
72 echo $'binary \xff';
73 echo '"json\n\u03bc"';
74 echo "u'j8 u \\u{3bc}'";
75 echo "b'j8 b \\y{ff'";
76)
77
78pp line (b)
79
80## STDOUT:
81## END
82
83#### for loop using @(seq $n)
84shopt -s oil:upgrade
85
86for x in @(seq 3) {
87 echo "[$x]"
88}
89for x in @(seq 3) {
90 argv.py z @[glob("[$x]")]
91}
92## STDOUT:
93[1]
94[2]
95[3]
96['z']
97['z']
98['z']
99## END
100
101#### @() can't start in the middle of the word
102shopt -s extglob # this makes it match in bash
103shopt -s oil:upgrade
104
105# This is currently a RUNTIME error when simple_word_eval is on
106
107touch foo.py
108echo f@(*.py)
109## status: 1
110## STDOUT:
111## END
112## OK bash status: 0
113## OK bash STDOUT:
114foo.py
115## END
116
117#### @() can't have any tokens after it
118shopt -s oil:upgrade
119
120write -- @(seq 2)
121write -- @(seq 3)x
122## status: 2
123## STDOUT:
1241
1252
126## END