| 1 | ## oils_failures_allowed: 0
 | 
| 2 | ## compare_shells: dash bash mksh zsh ash
 | 
| 3 | 
 | 
| 4 | # TODO mapfile options: -c, -C, -u, etc.
 | 
| 5 | 
 | 
| 6 | #### echo dashes
 | 
| 7 | echo -
 | 
| 8 | echo --
 | 
| 9 | echo ---
 | 
| 10 | ## stdout-json: "-\n--\n---\n"
 | 
| 11 | ## BUG zsh stdout-json: "\n--\n---\n"
 | 
| 12 | 
 | 
| 13 | #### echo backslashes
 | 
| 14 | echo \\
 | 
| 15 | echo '\'
 | 
| 16 | echo '\\'
 | 
| 17 | echo "\\"
 | 
| 18 | ## STDOUT:
 | 
| 19 | \
 | 
| 20 | \
 | 
| 21 | \\
 | 
| 22 | \
 | 
| 23 | ## BUG dash/mksh/zsh STDOUT:
 | 
| 24 | \
 | 
| 25 | \
 | 
| 26 | \
 | 
| 27 | \
 | 
| 28 | ## END
 | 
| 29 | 
 | 
| 30 | #### echo -e backslashes
 | 
| 31 | echo -e \\
 | 
| 32 | echo -e '\'
 | 
| 33 | echo -e '\\'
 | 
| 34 | echo -e "\\"
 | 
| 35 | echo
 | 
| 36 | 
 | 
| 37 | # backslash at end of line
 | 
| 38 | echo -e '\
 | 
| 39 | line2'
 | 
| 40 | ## STDOUT:
 | 
| 41 | \
 | 
| 42 | \
 | 
| 43 | \
 | 
| 44 | \
 | 
| 45 | 
 | 
| 46 | \
 | 
| 47 | line2
 | 
| 48 | ## N-I dash STDOUT:
 | 
| 49 | -e \
 | 
| 50 | -e \
 | 
| 51 | -e \
 | 
| 52 | -e \
 | 
| 53 | 
 | 
| 54 | -e \
 | 
| 55 | line2
 | 
| 56 | ## END
 | 
| 57 | 
 | 
| 58 | #### echo builtin should disallow typed args - literal
 | 
| 59 | echo (42)
 | 
| 60 | ## status: 2
 | 
| 61 | ## OK mksh/zsh status: 1
 | 
| 62 | ## STDOUT:
 | 
| 63 | ## END
 | 
| 64 | 
 | 
| 65 | #### echo builtin should disallow typed args - variable
 | 
| 66 | var x = 43
 | 
| 67 | echo (x)
 | 
| 68 | ## status: 2
 | 
| 69 | ## OK mksh/zsh status: 1
 | 
| 70 | ## STDOUT:
 | 
| 71 | ## END
 | 
| 72 | 
 | 
| 73 | #### echo -en
 | 
| 74 | echo -en 'abc\ndef\n'
 | 
| 75 | ## stdout-json: "abc\ndef\n"
 | 
| 76 | ## N-I dash stdout-json: "-en abc\ndef\n\n"
 | 
| 77 | 
 | 
| 78 | #### echo -ez (invalid flag)
 | 
| 79 | # bash differs from the other three shells, but its behavior is possibly more
 | 
| 80 | # sensible, if you're going to ignore the error.  It doesn't make sense for
 | 
| 81 | # the 'e' to mean 2 different things simultaneously: flag and literal to be
 | 
| 82 | # printed.
 | 
| 83 | echo -ez 'abc\n'
 | 
| 84 | ## stdout-json: "-ez abc\\n\n"
 | 
| 85 | ## OK dash/mksh/zsh stdout-json: "-ez abc\n\n"
 | 
| 86 | 
 | 
| 87 | #### echo -e with embedded newline
 | 
| 88 | flags='-e'
 | 
| 89 | case $SH in dash) flags='' ;; esac
 | 
| 90 | 
 | 
| 91 | echo $flags 'foo
 | 
| 92 | bar'
 | 
| 93 | ## STDOUT:
 | 
| 94 | foo
 | 
| 95 | bar
 | 
| 96 | ## END
 | 
| 97 | 
 | 
| 98 | #### echo -e line continuation
 | 
| 99 | flags='-e'
 | 
| 100 | case $SH in dash) flags='' ;; esac
 | 
| 101 | 
 | 
| 102 | echo $flags 'foo\
 | 
| 103 | bar'
 | 
| 104 | ## STDOUT:
 | 
| 105 | foo\
 | 
| 106 | bar
 | 
| 107 | ## END
 | 
| 108 | 
 | 
| 109 | #### echo -e with C escapes
 | 
| 110 | # https://www.gnu.org/software/bash/manual/bashref.html#Bourne-Shell-Builtins
 | 
| 111 | # not sure why \c is like NUL?
 | 
| 112 | # zsh doesn't allow \E for some reason.
 | 
| 113 | echo -e '\a\b\d\e\f'
 | 
| 114 | ## stdout-json: "\u0007\u0008\\d\u001b\u000c\n"
 | 
| 115 | ## N-I dash stdout-json: "-e \u0007\u0008\\d\\e\u000c\n"
 | 
| 116 | 
 | 
| 117 | #### echo -e with whitespace C escapes
 | 
| 118 | echo -e '\n\r\t\v'
 | 
| 119 | ## stdout-json: "\n\r\t\u000b\n"
 | 
| 120 | ## N-I dash stdout-json: "-e \n\r\t\u000b\n"
 | 
| 121 | 
 | 
| 122 | #### \0
 | 
| 123 | echo -e 'ab\0cd'
 | 
| 124 | ## stdout-json: "ab\u0000cd\n"
 | 
| 125 | ## N-I dash stdout-json: "-e ab\u0000cd\n"
 | 
| 126 | 
 | 
| 127 | #### \c stops processing input
 | 
| 128 | flags='-e'
 | 
| 129 | case $SH in dash) flags='' ;; esac
 | 
| 130 | 
 | 
| 131 | echo $flags xy  'ab\cde'  'zzz'
 | 
| 132 | ## stdout-json: "xy ab"
 | 
| 133 | ## N-I mksh stdout-json: "xy abde zzz"
 | 
| 134 | 
 | 
| 135 | #### echo -e with hex escape
 | 
| 136 | echo -e 'abcd\x65f'
 | 
| 137 | ## stdout-json: "abcdef\n"
 | 
| 138 | ## N-I dash stdout-json: "-e abcd\\x65f\n"
 | 
| 139 | 
 | 
| 140 | #### echo -e with octal escape
 | 
| 141 | flags='-e'
 | 
| 142 | case $SH in dash) flags='' ;; esac
 | 
| 143 | 
 | 
| 144 | echo $flags 'abcd\044e'
 | 
| 145 | ## stdout-json: "abcd$e\n"
 | 
| 146 | 
 | 
| 147 | #### echo -e with 4 digit unicode escape
 | 
| 148 | flags='-e'
 | 
| 149 | case $SH in dash) flags='' ;; esac
 | 
| 150 | 
 | 
| 151 | echo $flags 'abcd\u0065f'
 | 
| 152 | ## STDOUT:
 | 
| 153 | abcdef
 | 
| 154 | ## END
 | 
| 155 | ## N-I dash/ash stdout-json: "abcd\\u0065f\n"
 | 
| 156 | 
 | 
| 157 | #### echo -e with 8 digit unicode escape
 | 
| 158 | flags='-e'
 | 
| 159 | case $SH in dash) flags='' ;; esac
 | 
| 160 | 
 | 
| 161 | echo $flags 'abcd\U00000065f'
 | 
| 162 | ## STDOUT:
 | 
| 163 | abcdef
 | 
| 164 | ## END
 | 
| 165 | ## N-I dash/ash stdout-json: "abcd\\U00000065f\n"
 | 
| 166 | 
 | 
| 167 | #### \0377 is the highest octal byte
 | 
| 168 | echo -en '\03777' | od -A n -t x1 | sed 's/ \+/ /g'
 | 
| 169 | ## stdout-json: " ff 37\n"
 | 
| 170 | ## N-I dash stdout-json: " 2d 65 6e 20 ff 37 0a\n"
 | 
| 171 | 
 | 
| 172 | #### \0400 is one more than the highest octal byte
 | 
| 173 | # It is 256 % 256 which gets interpreted as a NUL byte.
 | 
| 174 | echo -en '\04000' | od -A n -t x1 | sed 's/ \+/ /g'
 | 
| 175 | ## stdout-json: " 00 30\n"
 | 
| 176 | ## BUG ash stdout-json: " 20 30 30\n"
 | 
| 177 | ## N-I dash stdout-json: " 2d 65 6e 20 00 30 0a\n"
 | 
| 178 | 
 | 
| 179 | #### \0777 is out of range
 | 
| 180 | flags='-en'
 | 
| 181 | case $SH in dash) flags='-n' ;; esac
 | 
| 182 | 
 | 
| 183 | echo $flags '\0777' | od -A n -t x1 | sed 's/ \+/ /g'
 | 
| 184 | ## stdout-json: " ff\n"
 | 
| 185 | ## BUG mksh stdout-json: " c3 bf\n"
 | 
| 186 | ## BUG ash stdout-json: " 3f 37\n"
 | 
| 187 | 
 | 
| 188 | #### incomplete hex escape
 | 
| 189 | echo -en 'abcd\x6' | od -A n -c | sed 's/ \+/ /g'
 | 
| 190 | ## stdout-json: " a b c d 006\n"
 | 
| 191 | ## N-I dash stdout-json: " - e n a b c d \\ x 6 \\n\n"
 | 
| 192 | 
 | 
| 193 | #### \x
 | 
| 194 | # I consider mksh and zsh a bug because \x is not an escape
 | 
| 195 | echo -e '\x' '\xg' | od -A n -c | sed 's/ \+/ /g'
 | 
| 196 | ## stdout-json: " \\ x \\ x g \\n\n"
 | 
| 197 | ## N-I dash stdout-json: " - e \\ x \\ x g \\n\n"
 | 
| 198 | ## BUG mksh/zsh stdout-json: " \\0 \\0 g \\n\n"
 | 
| 199 | 
 | 
| 200 | #### incomplete octal escape
 | 
| 201 | flags='-en'
 | 
| 202 | case $SH in dash) flags='-n' ;; esac
 | 
| 203 | 
 | 
| 204 | echo $flags 'abcd\04' | od -A n -c | sed 's/ \+/ /g'
 | 
| 205 | ## stdout-json: " a b c d 004\n"
 | 
| 206 | 
 | 
| 207 | #### incomplete unicode escape
 | 
| 208 | echo -en 'abcd\u006' | od -A n -c | sed 's/ \+/ /g'
 | 
| 209 | ## stdout-json: " a b c d 006\n"
 | 
| 210 | ## N-I dash stdout-json: " - e n a b c d \\ u 0 0 6 \\n\n"
 | 
| 211 | ## BUG ash stdout-json: " a b c d \\ u 0 0 6\n"
 | 
| 212 | 
 | 
| 213 | #### \u6
 | 
| 214 | flags='-en'
 | 
| 215 | case $SH in dash) flags='-n' ;; esac
 | 
| 216 | 
 | 
| 217 | echo $flags '\u6' | od -A n -c | sed 's/ \+/ /g'
 | 
| 218 | ## stdout-json: " 006\n"
 | 
| 219 | ## N-I dash/ash stdout-json: " \\ u 6\n"
 | 
| 220 | 
 | 
| 221 | #### \0 \1 \8
 | 
| 222 | # \0 is special, but \1 isn't in bash
 | 
| 223 | # \1 is special in dash!  geez
 | 
| 224 | flags='-en'
 | 
| 225 | case $SH in dash) flags='-n' ;; esac
 | 
| 226 | 
 | 
| 227 | echo $flags '\0' '\1' '\8' | od -A n -c | sed 's/ \+/ /g'
 | 
| 228 | ## stdout-json: " \\0 \\ 1 \\ 8\n"
 | 
| 229 | ## BUG dash/ash stdout-json: " \\0 001 \\ 8\n"
 | 
| 230 | 
 | 
| 231 | 
 | 
| 232 | #### echo to redirected directory is an error
 | 
| 233 | mkdir -p dir
 | 
| 234 | 
 | 
| 235 | echo foo > ./dir
 | 
| 236 | echo status=$?
 | 
| 237 | printf foo > ./dir
 | 
| 238 | echo status=$?
 | 
| 239 | 
 | 
| 240 | ## STDOUT:
 | 
| 241 | status=1
 | 
| 242 | status=1
 | 
| 243 | ## END
 | 
| 244 | ## OK dash STDOUT:
 | 
| 245 | status=2
 | 
| 246 | status=2
 | 
| 247 | ## END
 | 
| 248 | 
 |