簡體   English   中英

bash - 引號中的變量

[英]bash - variables in quotes

我正在嘗試創建一個bash函數來自動添加未處理或修改的所有內容在我的工作樹中,提交它並推送。

這就是它的樣子:

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

但是,當我測試它時,我得到:

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

如何讓變量周圍的引號正確運行?

你不應該逃避報價。 我也建議引用所有論點。 也許你的分支有一個空間,誰知道呢? 如果你在一行中放入更多的語句,你只需要分號。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM