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

Re: protect spaces and/or globs



On Tue, 2021-02-09 at 12:42 -0800, Ray Andrews wrote:
> 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

This is what arrays are for.

unsetopt shwordsplit # leave poor unsuspecting spaces alone
filespec=()

while [[ -n $1 ]]; do
  filespec+=($1)
  shift
done

In this case, actually, all you're doing is the equivalent of
a single array assignment.

filespec=("$@")

pws





Messages sorted by: Reverse Date, Date, Thread, Author