2011-01-14 62 views
0

我在下面的bash功能我的〜/ .bashrc庆典如何使命令工作

function gitlab { 
    MSG='first commit' 
    CMD="git commit -m '${MSG}'" 
    echo $CMD 
    $CMD 
} 

下面是结果

$ gitlab 
git commit -m 'first commit' 
error: pathspec 'commit'' did not match any file(s) known to git. 

有什么解决?

回答

0

尝试把你的提交信息在双引号,单引号和双引号意味着不同的事情抨击。

function gitlab { 
    MSG="first commit" 
    CMD=`git commit -m \"${MSG}\"` 
    echo $CMD 
    $CMD 
} 
+1

双引号逃逸单引号,抑制了抑制。 – 2011-01-14 21:17:19

+0

这肯定不会起作用 – Elalfer 2011-01-14 21:18:19

0

我想你应该使用的\"代替'所以它应该是这样的:

CMD="git commit -m \"${MSG}\"" 
1

肯定读BashFAQ/050是伊格纳西奥挂钩。

你可以试试这个,虽然:

function gitlab { 
    local PS4='Running: ' 
    local msg='first commit' 
    bash -xc "git commit -m '$msg'" 
}