Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
protect spaces and/or globs
- X-seq: zsh-users 26477
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: protect spaces and/or globs
- Date: Tue, 9 Feb 2021 12:42:08 -0800
- Archived-at: <https://zsh.org/users/26477>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-02/a417e71d-f1dd-73ab-6ef0-7ff34e0804fc%40eastlink.ca>
- List-id: <zsh-users.zsh.org>
grep allow multiple filespecs of course, and if there are spaces they
have to be quoted naturally:
$ grep 'some string' filename 'filename with spaces' more_files*
My wrapper around grep has a problem with that tho because when I'm
grabbing the filespecs if I do something like this:
while [[ -n "$1" ]]; do
ffilespec+=" $1"
shift
done
Obviously the final list of files is chaos once the original enclosing
single quotes are stripped off as they are. Trying:
while [[ -n "'$1'" ]]; do
... as a brute force addition of single quotes works fine with filenames
with spaces but it also kills any glob expansions. Can I have it both
ways? I think I need to preserve any single quotes I add on CL verbatim
rather than trying to add them myself in the code. The various (q)
family flags don't seem to work. The closest I can get is to both
single quote and backslash the spaces as the input to my wrapper:
g 'some string' filename 'filename\ with\ spaces' more_files*
... and that's not so bad, but I'm betting there's an elegant way. Hafta
somehow not break the middle filespec on those spaces even without the
backslashes. And preserve the single quotes. Basically the arguments
should pass thru the function absolutely unmolested and grep should get
them exactly as I type them.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author