zsh-users
 help / color / mirror / code / Atom feed
* protect spaces and/or globs
@ 2021-02-09 20:42 Ray Andrews
  2021-02-09 21:05 ` Lawrence Velázquez
  2021-02-09 21:08 ` Peter Stephenson
  0 siblings, 2 replies; 23+ messages in thread
From: Ray Andrews @ 2021-02-09 20:42 UTC (permalink / raw)
  To: Zsh Users

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.





^ permalink raw reply	[flat|nested] 23+ messages in thread

end of thread, other threads:[~2021-02-11 19:49 UTC | newest]

Thread overview: 23+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-09 20:42 protect spaces and/or globs Ray Andrews
2021-02-09 21:05 ` Lawrence Velázquez
2021-02-09 21:08 ` Peter Stephenson
2021-02-09 23:45   ` Ray Andrews
2021-02-10  0:22     ` Lawrence Velázquez
2021-02-10  0:51       ` Ray Andrews
2021-02-10  1:46         ` Lawrence Velázquez
2021-02-10  2:25           ` Ray Andrews
2021-02-10  2:52             ` Lawrence Velázquez
2021-02-10  1:52         ` Greg Klanderman
2021-02-10  2:29           ` Ray Andrews
2021-02-10 15:18           ` Ray Andrews
2021-02-10 15:47             ` Peter Stephenson
2021-02-10 16:19               ` Ray Andrews
2021-02-10 16:29                 ` Peter Stephenson
2021-02-10 20:53                   ` Ray Andrews
2021-02-10 22:14                     ` Bart Schaefer
2021-02-11 16:31                       ` Ray Andrews
2021-02-11 17:19                         ` Lawrence Velázquez
2021-02-11 19:48                           ` Ray Andrews
2021-02-10 18:08                 ` Bart Schaefer
2021-02-10 20:56                   ` Ray Andrews
2021-02-10 16:28             ` Lawrence Velázquez

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).