2011-11-06 97 views
1

我试图让工作别名git的承诺bash脚本不使用多个参数

function gcam() { 
    git commit -a -m [email protected] ; 
    git status 
} 

当我调用命令gcam 'something'它工作正常,但如果消息有一个空间在中间,像gcam 'new commit'出现的消息Paths with -a does not make sense

我一直在寻找this solution,但它不为我工作,因为我使用[email protected]和不使用[email protected]$1。为什么?只是如果我需要传递一个额外的参数给git commit。

任何想法,使其工作呢?

在此先感谢

回答

3

@Mat是说对了一半:你应该双引号的[email protected],则引用消息也是如此。 "[email protected]"扩展到参数列表,每一个单独的字(即就好像每一个参数被单独引用):

function gcam() { 
    git commit -a -m "[email protected]" 
    git status 
} 

gcam "commit message" -v 

这并不等同:

git commit -a -m "commit message" -v 
git status