1 | #
|
2 | # Tests for the blog.
|
3 | #
|
4 | # Fun game: try to come up with an expression that behaves differently on ALL
|
5 | # FOUR shells.
|
6 |
|
7 | #### ${##}
|
8 | set -- $(seq 25)
|
9 | echo ${##}
|
10 | ## stdout: 2
|
11 |
|
12 | #### ${###}
|
13 | set -- $(seq 25)
|
14 | echo ${###}
|
15 | ## stdout: 25
|
16 | ## N-I osh stdout-json: ""
|
17 | ## N-I osh status: 2
|
18 |
|
19 | #### ${####}
|
20 | set -- $(seq 25)
|
21 | echo ${####}
|
22 | ## stdout: 25
|
23 | ## N-I osh stdout-json: ""
|
24 | ## N-I osh status: 2
|
25 |
|
26 | #### ${##2}
|
27 | set -- $(seq 25)
|
28 | echo ${##2}
|
29 | ## stdout: 5
|
30 | ## N-I osh stdout-json: ""
|
31 | ## N-I osh status: 2
|
32 |
|
33 | #### ${###2}
|
34 | set -- $(seq 25)
|
35 | echo ${###2}
|
36 | ## stdout: 5
|
37 | ## BUG mksh stdout: 25
|
38 | ## N-I osh stdout-json: ""
|
39 | ## N-I osh status: 2
|
40 |
|
41 | #### ${1####}
|
42 | set -- '####'
|
43 | echo ${1####}
|
44 | ## stdout: ##
|
45 |
|
46 | #### ${1#'###'}
|
47 | set -- '####'
|
48 | echo ${1#'###'}
|
49 | ## stdout: #
|
50 |
|
51 | #### ${#1#'###'}
|
52 | set -- '####'
|
53 | echo ${#1#'###'}
|
54 | # dash and zsh accept; mksh/bash/osh don't.
|
55 | ## status: 2
|
56 | ## stdout-json: ""
|
57 | ## OK dash/zsh status: 0
|
58 | ## OK dash stdout: 4
|
59 | ## OK zsh stdout: 1
|
60 | ## N-I bash/mksh status: 1
|
61 |
|
62 | #### Julia example from spec/oil-user-feedback
|
63 |
|
64 | case $SH in (dash|mksh|zsh) exit ;; esac
|
65 |
|
66 | git-branch-merged() {
|
67 | cat <<EOF
|
68 | foo
|
69 | * bar
|
70 | baz
|
71 | master
|
72 | EOF
|
73 | }
|
74 |
|
75 | shopt -s lastpipe # required for bash, not OSH
|
76 |
|
77 | branches=() # dangerous when set -e is on
|
78 | git-branch-merged | while read -r line; do
|
79 | line=${line# *} # strip leading spaces
|
80 | if [[ $line != 'master' && ! ${line:0:1} == '*' ]]; then
|
81 | branches+=("$line")
|
82 | fi
|
83 | done
|
84 |
|
85 | if [[ ${#branches[@]} -eq 0 ]]; then
|
86 | echo "No merged branches"
|
87 | else
|
88 | echo git branch -D "${branches[@]}"
|
89 | fi
|
90 |
|
91 | ## STDOUT:
|
92 | git branch -D foo baz
|
93 | ## END
|
94 | ## N-I dash/mksh/zsh STDOUT:
|
95 | ## END
|