bash - 引号中的变量

bash - variables in quotes

我正在尝试创建一个 bash 函数来自动添加我的工作树中所有未跟踪或修改的内容,提交并推送。

这是它的样子:

gcp() {
    git add -- .;
    git commit -m \"\";
    git push origin ;
}

然而,当我测试它时,我得到:

$ gcp "test this" master
error: pathspec 'this"' did not match any file(s) known to git.

如何让变量周围的引号正确运行?

你不应该转义引号。我还建议引用所有论点。也许您的分支机构中有一个 space,谁知道呢?如果在一行中放置更多语句,则只需要分号。

gcp() {
    git add -- .
    git commit -m ""
    git push origin ""
}