I want to add verbosity to my bash function by printing the command that it will run. What is the best way to print all arguments $@ inline?
ggtest ()
{
echo 'git grep -n $@ -- "src/tests/*"'
git grep -n "$@" -- "src/tests/*";
}
So that I can see an output such as:
$ ggtest "models and views"
git grep -n "models and views" -- "src/tests/*"
...
An overcomplicated version you can cut down to support only the specific shell releases you need support for:
Note that in current shell releases
printf %qwill use backslashes rather than quotes for escaping, so it would changeggtest "some string"to havesome\ stringin the logs; not the worst thing in the word, but it's less pretty than${array[*]@Q}'s representation