| 1 | ## compare_shells: dash bash mksh zsh
|
| 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
|
| 62 |
|
| 63 | #### Julia example from spec/oil-user-feedback
|
| 64 |
|
| 65 | case $SH in (dash|mksh|zsh) exit ;; esac
|
| 66 |
|
| 67 | git-branch-merged() {
|
| 68 | cat <<EOF
|
| 69 | foo
|
| 70 | * bar
|
| 71 | baz
|
| 72 | master
|
| 73 | EOF
|
| 74 | }
|
| 75 |
|
| 76 | shopt -s lastpipe # required for bash, not OSH
|
| 77 |
|
| 78 | branches=() # dangerous when set -e is on
|
| 79 | git-branch-merged | while read -r line; do
|
| 80 | line=${line# *} # strip leading spaces
|
| 81 | if [[ $line != 'master' && ! ${line:0:1} == '*' ]]; then
|
| 82 | branches+=("$line")
|
| 83 | fi
|
| 84 | done
|
| 85 |
|
| 86 | if [[ ${#branches[@]} -eq 0 ]]; then
|
| 87 | echo "No merged branches"
|
| 88 | else
|
| 89 | echo git branch -D "${branches[@]}"
|
| 90 | fi
|
| 91 |
|
| 92 | ## STDOUT:
|
| 93 | git branch -D foo baz
|
| 94 | ## END
|
| 95 | ## N-I dash/mksh/zsh STDOUT:
|
| 96 | ## END
|