Motivation: I am building a command commitdeploy which I want to accept very raw shell input:
bash$ ./commitdeploy this is my commit message
So I have a script that looks like:
#!/bin/bash
...
git commit -a -m"$@" && ./deploy
Which produces:
fatal: Paths with -a does not make sense.
Here’s what I know:
$@ is the arg-list.
"$@" is the arg-list converted into a string that should show up as a single arg when used
My question is, what exactly is bash trying to send to git? If git is receiving "$@" as not a single arg then I think my characterization of "$@" above is incorrect. It looks like I need to stick more quotes in!
So, which one of the following, if any, are the right way, and why?
option 1: git commit -a -m"\"$@\""
option 2: git commit -a -m\""$@"\"
Use
"$*"instead of"$@"if you want everything in one argument.This is a POSIX feature, so it will work in all POSIX-compatible shells and is not a bash-ism.