This feels like an incredibly simple task, but I can't get it to work. I want to put the first 13 files in a directory into a .zip
archive. The obvious way to do this is
zip first13.zip $(ls | head -n 13)
But this fails because some of the filenames--which I can't change for stupid institutional reasons--have spaces in them. Replacing ls
with ls --quoting-style=shell-always
doesn't help (it actually makes things worse, because somehow zip
ends up looking for files that start and end with literal '
characters, and yet still parses the spaces...) and neither does
ls | head -n 13 | xargs zip first13.zip
Again, zip
parses the spaces.
Weirdly, zip all.zip ./*
works fine, so clearly some kind of escaping is possible, but I don't know how to replicate whatever zsh
does in its globbing.
In case there is more than one version of zip
out there, mine is the one that comes in Arch Linux's official zip
package, and identifies itself as Copyright (c) 1990-2008 Info-ZIP
. The shell is zsh
version 5.8.
ls
should be avoided to be parsed. – pLumo Jul 10 '20 at 08:16