Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

protect spaces and/or globs

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"

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