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

Re: Git grep command not interpreting flags correctly when an argument



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