1 |
# |
2 |
# Tests for pipelines. |
3 |
# NOTE: Grammatically, ! is part of the pipeline: |
4 |
# |
5 |
# pipeline : pipe_sequence |
6 |
# | Bang pipe_sequence |
7 |
|
8 |
#### Brace group in pipeline |
9 |
{ echo one; echo two; } | tac |
10 |
## stdout-json: "two\none\n" |
11 |
|
12 |
#### For loop starts pipeline |
13 |
for w in one two; do |
14 |
echo $w |
15 |
done | tac |
16 |
## stdout-json: "two\none\n" |
17 |
|
18 |
#### While Loop ends pipeline |
19 |
seq 3 | while read i |
20 |
do |
21 |
echo ".$i" |
22 |
done |
23 |
## stdout-json: ".1\n.2\n.3\n" |
24 |
|
25 |
#### Redirect in Pipeline |
26 |
echo hi 1>&2 | wc -l |
27 |
## stdout: 0 |
28 |
## BUG zsh stdout: 1 |
29 |
|
30 |
#### Pipeline comments |
31 |
echo abcd | # input |
32 |
# blank line |
33 |
tr a-z A-Z # transform |
34 |
## stdout: ABCD |
35 |
|
36 |
#### Exit code is last status |
37 |
echo a | egrep '[0-9]+' |
38 |
## status: 1 |
39 |
|
40 |
#### PIPESTATUS |
41 |
return3() { |
42 |
return 3 |
43 |
} |
44 |
{ sleep 0.03; exit 1; } | { sleep 0.02; exit 2; } | { sleep 0.01; return3; } |
45 |
echo ${PIPESTATUS[@]} |
46 |
## stdout: 1 2 3 |
47 |
## N-I dash status: 2 |
48 |
## N-I dash stdout-json: "" |
49 |
## N-I zsh status: 0 |
50 |
## N-I zsh stdout-json: "\n" |
51 |
|
52 |
#### PIPESTATUS with shopt -s lastpipe |
53 |
shopt -s lastpipe |
54 |
return3() { |
55 |
return 3 |
56 |
} |
57 |
{ sleep 0.03; exit 1; } | { sleep 0.02; exit 2; } | { sleep 0.01; return3; } |
58 |
echo ${PIPESTATUS[@]} |
59 |
## stdout: 1 2 3 |
60 |
## N-I dash status: 2 |
61 |
## N-I dash stdout-json: "" |
62 |
## N-I zsh status: 0 |
63 |
## N-I zsh stdout-json: "\n" |
64 |
|
65 |
#### |& |
66 |
stdout_stderr.py |& cat |
67 |
## STDOUT: |
68 |
STDERR |
69 |
STDOUT |
70 |
## END |
71 |
## status: 0 |
72 |
## N-I dash/mksh stdout-json: "" |
73 |
## N-I dash status: 2 |
74 |
## N-I osh stdout-json: "" |
75 |
## N-I osh status: 1 |
76 |
|
77 |
#### ! turns non-zero into zero |
78 |
! $SH -c 'exit 42'; echo $? |
79 |
## stdout: 0 |
80 |
## status: 0 |
81 |
|
82 |
#### ! turns zero into 1 |
83 |
! $SH -c 'exit 0'; echo $? |
84 |
## stdout: 1 |
85 |
## status: 0 |
86 |
|
87 |
#### ! in if |
88 |
if ! echo hi; then |
89 |
echo TRUE |
90 |
else |
91 |
echo FALSE |
92 |
fi |
93 |
## stdout-json: "hi\nFALSE\n" |
94 |
## status: 0 |
95 |
|
96 |
#### ! with || |
97 |
! echo hi || echo FAILED |
98 |
## stdout-json: "hi\nFAILED\n" |
99 |
## status: 0 |
100 |
|
101 |
#### ! with { } |
102 |
! { echo 1; echo 2; } || echo FAILED |
103 |
## stdout-json: "1\n2\nFAILED\n" |
104 |
## status: 0 |
105 |
|
106 |
#### ! with ( ) |
107 |
! ( echo 1; echo 2 ) || echo FAILED |
108 |
## stdout-json: "1\n2\nFAILED\n" |
109 |
## status: 0 |
110 |
|
111 |
#### ! is not a command |
112 |
v='!' |
113 |
$v echo hi |
114 |
## status: 127 |
115 |
|
116 |
#### Evaluation of argv[0] in pipeline occurs in child |
117 |
${cmd=echo} hi | wc -l |
118 |
echo "cmd=$cmd" |
119 |
## STDOUT: |
120 |
1 |
121 |
cmd= |
122 |
## END |
123 |
## BUG zsh STDOUT: |
124 |
1 |
125 |
cmd=echo |
126 |
## END |
127 |
|
128 |
#### bash/dash/mksh run the last command is run in its own process |
129 |
echo hi | read line |
130 |
echo "line=$line" |
131 |
## stdout: line=hi |
132 |
## OK bash/dash/mksh stdout: line= |
133 |
|
134 |
#### shopt -s lastpipe (always on in OSH) |
135 |
shopt -s lastpipe |
136 |
echo hi | read line |
137 |
echo "line=$line" |
138 |
## stdout: line=hi |
139 |
## N-I dash/mksh stdout: line= |
140 |
|
141 |
#### shopt -s lastpipe (always on in OSH) |
142 |
shopt -s lastpipe |
143 |
i=0 |
144 |
seq 3 | while read line; do |
145 |
(( i++ )) |
146 |
done |
147 |
echo i=$i |
148 |
## stdout: i=3 |
149 |
## N-I dash/mksh stdout: i=0 |
150 |
|
151 |
|
152 |
#### SIGPIPE causes pipeline to die (regression for issue #295) |
153 |
cat /dev/urandom | sleep 0.1 |
154 |
echo ${PIPESTATUS[@]} |
155 |
|
156 |
# hm bash gives '1 0' which seems wrong |
157 |
|
158 |
## STDOUT: |
159 |
141 0 |
160 |
## END |
161 |
## BUG bash STDOUT: |
162 |
1 0 |
163 |
## END |
164 |
## N-I zsh stdout: |
165 |
## N-I dash status: 2 |
166 |
## N-I dash stdout-json: "" |