I am trying to amend the behavior of git, using the approach outlined here, but I am stumbling on how to properly pass on the contents of $@ without losing the quotes of the original input.
Basically, I have this:
# foo.sh
#!/bin/bash
cmd=$1
shift
args=$@
if [ $cmd == "bar" ]; then args=('--baz' "${args[@]}"); fi
echo git $cmd ${args[@]}
But when I run ./foo.sh bar -a "one two three", it outputs (and thus would have run), ./foo.sh bar --baz -a one two, rather than ./foo.sh bar --baz -a "one two" as I would have needed.
I can't figure out how to properly pass on $@ to another command and preserve quoted arguments. Is it possible? How?