Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Git grep command not interpreting flags correctly when an argument
- X-seq: zsh-workers 44327
- From: Matthew Martin <phy1729@xxxxxxxxx>
- To: Sam Houston <sehouston3@xxxxxxxxx>
- Subject: Re: Git grep command not interpreting flags correctly when an argument
- Date: Sun, 19 May 2019 13:32:11 -0500
- Cc: zsh-workers@xxxxxxx
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to:user-agent; bh=bRTQjECF0E1YJDbe3T6T6ThVtNFozwID35vRO3CC5uQ=; b=g6a8+ZaB9TKjXK4OK0B6NQ6vztggbvlJzIphigdNuLqPhydiB6KGilBWTpB842tSH1 xsQAJ4Y21fsJ6Q6lORa3SMj27hrODXxnXmc06shKvENdtqpcbcSWtPrZXPrwczfTTD6U OwRP+QYAAaWpmY4IBidguWMLhBofO2GKexClldO6COPjECPdOSX0lxQ+ipr/KZNAV+H9 S7VpOFFO/A5noky9HZ6O19GSHXmBLSzdUz8b9lTZ05gKc7MEPHijrKIoGKjO89o5tjn0 R2UCsOySVZwTUC0k+4tLgp1pRfsAY3tu3vwkkRN1do8XvmS6D27gPqwxHZXZRDzmi8Ly 9wZQ==
- In-reply-to: <CADbM1Mo6iqa=YcEFCw67FVOhZisX9ioBsdtzTcVmjEOgErebtA@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-followup-to: Sam Houston <sehouston3@xxxxxxxxx>, zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CADbM1Mo6iqa=YcEFCw67FVOhZisX9ioBsdtzTcVmjEOgErebtA@mail.gmail.com>
On Sun, May 19, 2019 at 07:09:22PM +0100, Sam Houston wrote:
> In a `bash` shell, in some empty directory, I can run the commands:
>
> ```bash
> git init
> echo "pattern" > file.txt
> FLAGS="--untracked --color"
> git grep $FLAGS pattern
> ```
>
> And see the output:
>
> ```
> file.txt:pattern
> ```
>
> But in a `zsh` shell, when I run the same commands, I get the following
> error:
>
> ```
> error: unknown option `untracked --color'
> ```
The better way (both in zsh and in bash) would be to use an array.
flags=(--untracked --color)
git grep "${flags[@]}" pattern
# git grep $flags pattern would also work, but just in zsh
Relying on word splitting means that arguments that contain spaces or
other IFS characters are mangled into two or more arguments.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author