1 #!/usr/bin/env bash
2 #
3 # POSIX rule about special builtins pointed at:
4 #
5 # https://www.reddit.com/r/oilshell/comments/5ykpi3/oildev_is_alive/
6
7 ### : is special and prefix assignments persist after special builtins
8 # Bash only implements it behind the posix option
9 test -n "$BASH_VERSION" && set -o posix
10 foo=bar :
11 echo $foo
12 # stdout: bar
13
14 ### true is not special
15 foo=bar true
16 echo $foo
17 # stdout:
18
19 ### Shift is special and the whole script exits if it returns non-zero
20 test -n "$BASH_VERSION" && set -o posix
21 set -- a b
22 shift 3
23 echo status=$?
24 # stdout-json: ""
25 # status: 1
26 # OK dash status: 2
27 # BUG bash status: 0
28 # BUG bash stdout-json: "status=1\n"
29
30 ### Special builtins can't be redefined as functions
31 # bash manual says they are 'found before' functions.
32 test -n "$BASH_VERSION" && set -o posix
33 export() {
34 echo 'export func'
35 }
36 export hi
37 echo status=$?
38 # status: 2
39 # BUG mksh status: 0
40 # BUG mksh stdout: status=0
41
42 ### Non-special builtins CAN be redefined as functions
43 test -n "$BASH_VERSION" && set -o posix
44 true() {
45 echo 'true func'
46 }
47 true hi
48 echo status=$?
49 # stdout-json: "true func\nstatus=0\n"