1 #!/usr/bin/env bash
2 #
3 # Tests for the blog.
4 #
5 # Fun game: try to come up with an expression that behaves differently on ALL
6 # FOUR shells.
7
8 #### ${##}
9 set -- $(seq 25)
10 echo ${##}
11 ## stdout: 2
12
13 #### ${###}
14 set -- $(seq 25)
15 echo ${###}
16 ## stdout: 25
17 ## N-I osh stdout-json: ""
18 ## N-I osh status: 2
19
20 #### ${####}
21 set -- $(seq 25)
22 echo ${####}
23 ## stdout: 25
24 ## N-I osh stdout-json: ""
25 ## N-I osh status: 2
26
27 #### ${##2}
28 set -- $(seq 25)
29 echo ${##2}
30 ## stdout: 5
31 ## N-I osh stdout-json: ""
32 ## N-I osh status: 2
33
34 #### ${###2}
35 set -- $(seq 25)
36 echo ${###2}
37 ## stdout: 5
38 ## BUG mksh stdout: 25
39 ## N-I osh stdout-json: ""
40 ## N-I osh status: 2
41
42 #### ${1####}
43 set -- '####'
44 echo ${1####}
45 ## stdout: ##
46
47 #### ${1#'###'}
48 set -- '####'
49 echo ${1#'###'}
50 ## stdout: #
51
52 #### ${#1#'###'}
53 set -- '####'
54 echo ${#1#'###'}
55 # dash and zsh accept; mksh/bash/osh don't.
56 ## status: 2
57 ## stdout-json: ""
58 ## OK dash/zsh status: 0
59 ## OK dash stdout: 4
60 ## OK zsh stdout: 1
61 ## N-I bash/mksh status: 1