Skip to main content
9 events
when toggle format what by license comment
Jan 30, 2020 at 9:33 comment added Stéphane Chazelas mkdir -p $'/tmp/\n/etc/shadow\n/file~'. There, you've seen it now ;-), the excuse no longer stands and your rm -f (find /tmp -name '*~') will remove /etc/shadow. It's not about how common it is or not, it's about whether it's possible or not. File paths are sequences of bytes other than 0. To handle them reliably, you have to treat them as binary blobs.
Jan 29, 2020 at 21:44 comment added enigmaticPhysicist Meh. Splitting on newlines is good enough. Like the answer says, newlines in filenames are extremely rare. I have literally never seen it happen in 17 years. And newlines are way more convenient separators than nuls.
Jan 29, 2020 at 9:01 comment added Stéphane Chazelas Assuming you meant the same without the quotes, that's not "right", that's splitting on lines, it's just a different choice. zsh splits on words by default (like all other shells) and can be told to split on lines or on NULs, either via $IFS or via explicit operators (f and 0 parameter expansion flags). For arbitrary file names, splitting by word or splitting by line is equally wrong, you need to split on NUL or parse some encoding, which fish can't do. In zsh, that's IFS=$'\0'; ls -ld -- $(printf '%s\0' "$file1" "$file2") or ls -ld -- ${(0)"$(printf '%s\0' "$file1" "$file2")"}
Jan 29, 2020 at 2:04 history edited enigmaticPhysicist CC BY-SA 4.0
zsh is also dumb. I am disappoint.
Jan 29, 2020 at 2:04 comment added enigmaticPhysicist Yeah, zsh doesn't do the right thing when you do ls "$(echo test; echo other test)". Only fish does the right thing.
Jan 29, 2020 at 1:57 comment added enigmaticPhysicist aw, crap. OK this works: $ f='not there'<ret>$ ls $f<ret> but this doesn't: ls echo not there. OK looks like I need to update this a bit.
Jan 25, 2020 at 19:03 comment added Stéphane Chazelas zsh splits on SPC, TAB, NL and NUL by default. The thing it doesn't do compared to bash is perform globbing on the result so wildcard characters in file names are not a problem. In zsh, you'd do IFS=$'\0'; vi $(locate -0 php.ini) or as I shown in my answer vi ${(0)"$(locate -0 php.ini)"} for an explicit splitting operator. Also note tcsh's vi "`locate php.ini`"
Jan 25, 2020 at 0:08 history edited enigmaticPhysicist CC BY-SA 4.0
I /guess/ there are occasions where you need to think about newlines in filenames.
Jan 25, 2020 at 0:01 history answered enigmaticPhysicist CC BY-SA 4.0