1 ## oils_failures_allowed: 2
2 ## compare_shells: dash bash mksh zsh ash
3
4 #### NUL bytes with echo -e
5 case $SH in (dash) exit ;; esac
6
7 echo -e '\0-'
8 #echo -e '\x00-'
9 #echo -e '\000-'
10
11 ## stdout-repr: "\x00-\n"
12 ## BUG zsh stdout-repr: "\x00\n"
13 ## N-I dash stdout-json: ""
14
15 #### NUL bytes in printf format
16 printf '\0\n'
17 ## stdout-repr: "\x00\n"
18
19 #### NUL bytes in printf value (OSH and zsh agree)
20 case $SH in (dash) exit ;; esac
21
22 nul=$'\0'
23 echo "$nul"
24 printf '%s\n' "$nul"
25
26 ## stdout-repr: "\n\n"
27 ## OK osh/zsh stdout-repr: "\x00\n\x00\n"
28 ## N-I dash stdout-json: ""
29
30
31
32 #### NUL bytes with echo $'\0' (OSH and zsh agree)
33
34 case $SH in (dash) exit ;; esac
35
36 # OSH agrees with ZSH -- so you have the ability to print NUL bytes without
37 # legacy echo -e
38
39 echo $'\0'
40
41 ## stdout-repr: "\n"
42 ## OK osh/zsh stdout-repr: "\0\n"
43 ## N-I dash stdout-json: ""
44
45
46 #### NUL bytes and IFS splitting
47 case $SH in (dash) exit ;; esac
48
49 argv.py $(echo -e '\0')
50 argv.py "$(echo -e '\0')"
51 argv.py $(echo -e 'a\0b')
52 argv.py "$(echo -e 'a\0b')"
53
54 ## STDOUT:
55 []
56 ['']
57 ['ab']
58 ['ab']
59 ## END
60 ## BUG zsh STDOUT:
61 ['', '']
62 ['']
63 ['a', 'b']
64 ['a']
65 ## END
66
67 ## N-I dash STDOUT:
68 ## END
69
70 #### NUL bytes with test -n
71
72 case $SH in (dash) exit ;; esac
73
74 # zsh is buggy here, weird
75 test -n $''
76 echo status=$?
77
78 test -n $'\0'
79 echo status=$?
80
81
82 ## STDOUT:
83 status=1
84 status=1
85 ## END
86 ## OK osh STDOUT:
87 status=1
88 status=0
89 ## END
90 ## BUG zsh STDOUT:
91 status=0
92 status=0
93 ## END
94
95 ## N-I dash STDOUT:
96 ## END
97
98
99 #### NUL bytes with test -f
100
101 case $SH in (dash) exit ;; esac
102
103
104 test -f $'\0'
105 echo status=$?
106
107 touch foo
108 test -f $'foo\0'
109 echo status=$?
110
111 test -f $'foo\0bar'
112 echo status=$?
113
114 test -f $'foobar'
115 echo status=$?
116
117
118 ## STDOUT:
119 status=1
120 status=0
121 status=0
122 status=1
123 ## END
124
125 ## OK ash STDOUT:
126 status=1
127 status=0
128 status=1
129 status=1
130 ## END
131
132 ## N-I dash STDOUT:
133 ## END
134
135
136 #### NUL bytes with ${#s} (OSH and zsh agree)
137
138 case $SH in (dash) exit ;; esac
139
140 empty=$''
141 nul=$'\0'
142
143 echo empty=${#empty}
144 echo nul=${#nul}
145
146
147 ## STDOUT:
148 empty=0
149 nul=0
150 ## END
151
152 ## OK osh/zsh STDOUT:
153 empty=0
154 nul=1
155 ## END
156
157 ## N-I dash STDOUT:
158 ## END