1 #!/bin/bash
2 #
3 # Tests for pipelines.
4 # NOTE: Grammatically, ! is part of the pipeline:
5 #
6 # pipeline : pipe_sequence
7 # | Bang pipe_sequence
8
9 ### Brace group in pipeline
10 { echo one; echo two; } | tac
11 # stdout-json: "two\none\n"
12
13 ### For loop in pipeline
14 for w in one two; do
15 echo $w
16 done | tac
17 # stdout-json: "two\none\n"
18
19 ### Exit code is last status
20 expr $0 : '.*/osh$' && exit 99 # Disabled because of spec-runner.sh issue
21 echo a | egrep '[0-9]+'
22 # status: 1
23
24 ### |&
25 stdout_stderr.py |& cat
26 # stdout-json: "STDERR\nSTDOUT\n"
27 # N-I dash/mksh stdout-json: ""
28
29 ### ! turns non-zero into zero
30 ! $SH -c 'exit 42'; echo $?
31 # stdout: 0
32 # status: 0
33
34 ### ! turns zero into 1
35 ! $SH -c 'exit 0'; echo $?
36 # stdout: 1
37 # status: 0
38
39 ### ! in if
40 if ! echo hi; then
41 echo TRUE
42 else
43 echo FALSE
44 fi
45 # stdout-json: "hi\nFALSE\n"
46 # status: 0
47
48 ### ! with ||
49 ! echo hi || echo FAILED
50 # stdout-json: "hi\nFAILED\n"
51 # status: 0
52
53 ### ! with { }
54 ! { echo 1; echo 2; } || echo FAILED
55 # stdout-json: "1\n2\nFAILED\n"
56 # status: 0
57
58 ### ! with ( )
59 ! ( echo 1; echo 2 ) || echo FAILED
60 # stdout-json: "1\n2\nFAILED\n"
61 # status: 0
62
63 ### ! is not a command
64 v='!'
65 $v echo hi
66 # status: 127
67