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

145 lines, 73 significant
1## oils_failures_allowed: 0
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
42# Not affected by IFS
43echo --
44shopt -s simple_word_eval
45write -- @(seq 3)
46
47echo --
48argv.py @(echo $x)
49
50## STDOUT:
511
522
533
54--
55['a', 'b', '', 'c']
56--
571
582
593
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
72var 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 " u' j8 u \\u{3bc} ' "
84 echo " b' j8 b \\u{3bc} ' "
85
86 # no prefix is like u''
87 echo " ' j8 no prefix \\u{3bc} ' "
88)
89
90json write (b)
91
92## STDOUT:
93[
94 "unquoted \"\" word",
95 " json μ ",
96 " j8 u μ ",
97 " j8 b μ ",
98 " j8 no prefix μ "
99]
100## END
101
102#### for loop using @(seq $n)
103shopt -s oil:upgrade
104
105for x in @(seq 3) {
106 echo "[$x]"
107}
108for x in @(seq 3) {
109 argv.py z @[glob("[$x]")]
110}
111## STDOUT:
112[1]
113[2]
114[3]
115['z']
116['z']
117['z']
118## END
119
120#### @() can't start in the middle of the word
121shopt -s extglob # this makes it match in bash
122shopt -s oil:upgrade
123
124# This is currently a RUNTIME error when simple_word_eval is on
125
126touch foo.py
127echo f@(*.py)
128## status: 1
129## STDOUT:
130## END
131## OK bash status: 0
132## OK bash STDOUT:
133foo.py
134## END
135
136#### @() can't have any tokens after it
137shopt -s oil:upgrade
138
139write -- @(seq 2)
140write -- @(seq 3)x
141## status: 2
142## STDOUT:
1431
1442
145## END