1

I'm trying to make an alias to git commit

function gcam() {
  git commit -a -m $@ ;
  git status
}

when I invoke the command with gcam 'something' it works correctly, but if the message has a space in the middle, like gcam 'new commit' appears the message Paths with -a does not make sense

I was looking this solution, but it doesn't work for me, because i'm using $@ and not $1.Why using $@? Is just if i need to pass an additional argument to git commit.

Any idea to make it works this?

Thanks in advance

1 Answer 1

3

@Mat is half right: you should double-quote the $@, then quote the message as well. "$@" expands to the list of arguments, each as a separate word (i.e. it's as though each argument was individually quoted):

function gcam() {
  git commit -a -m "$@"
  git status
}

gcam "commit message" -v

This does the equivalent of:

git commit -a -m "commit message" -v
git status
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.