Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: protect spaces and/or globs
- X-seq: zsh-users 26479
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: protect spaces and/or globs
- Date: Tue, 09 Feb 2021 21:08:47 +0000
- Archived-at: <https://zsh.org/users/26479>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-users/2021-02/dd78df51cf46d5bd3c48068bb2e870336780b31d.camel%40ntlworld.com>
- In-reply-to: <a417e71d-f1dd-73ab-6ef0-7ff34e0804fc@eastlink.ca>
- List-id: <zsh-users.zsh.org>
- References: <a417e71d-f1dd-73ab-6ef0-7ff34e0804fc@eastlink.ca>
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