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