Comment by abbeyj
14 days ago
> The Python one-liner is there because most modern shells refuse to create a non-UTF-8 filename for you.
Both `echo -ne 'weird\xffname\0' > list0` and `printf 'weird\xffname\0' > list0` seem to work fine for me on Linux. Is this macOS-specific?
> Both `echo -ne 'weird\xffname\0' > list0` and `printf 'weird\xffname\0' > list0` seem to work fine for me on Linux. Is this macOS-specific?
Neither of those create a non-UTF-8 filename. (Both files are named "list0", which is valid UTF-8.) They have non-UTF-8 content, but that's not weird.
But it's not too hard to get a non-UTF-8 filename:
Both zsh & bash support that syntax.
(You could also use process substitution with printf, but that's more steps than necessary. So, something closer to your example would be,
You can't put a \0 in the filename, as there's no way to pass that string in C.)