How to pass $@ as one argument to another command in a bash function?

I have this as a bash function:

function gits() { git grep -i -n --color $@ -- $(git rev-parse --show-toplevel); } 

If I run this:

 gits def add_crumb 

I want to:

 git grep -i -n --color "def add_crumb" -- $(git rev-parse --show-toplevel) 
+4
source share
1 answer

The purpose of $@ is to split it into separate arguments. Use "$*" if you do not want to. (Yes, with double quotes, you should also have them in " $@ " .)

+10
source

Source: https://habr.com/ru/post/1369398/


All Articles