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