簡體   English   中英

在 Bash 腳本中,函數的第二個參數未按預期處理

[英]In Bash Script Second Argument to Function is not Processed as Expected

嘗試結合 git - 在一個功能中添加/提交/推送。

gitacp testfile/testfile.py“測試”工作正常。

gitacp testfile/testfile.py "testing this" 導致這個錯誤。 錯誤:pathspec 'this' 與 git 已知的任何文件都不匹配。

由於某種原因,第二個參數中的字符串集沒有得到正確處理。

# Git add, commit and push
function gitacp {
    args=("$@")
    filepathname=${args[0]}
    comment=${args[1]}
    branchname=$(git status 2>/dev/null | head -n1 | cut -d" " -f3)
    git add ${filepathname}
    git commit -m ${comment}
    echo ${branchname}
    echo ${branchnmrmspc}
    echo ${comment}
    echo ${filepathname}
    git push --set-upstream origin ${branchname}
}
gitacp testfile/testfile.py "testing this" results in this error.
error: pathspec 'this' did not match any file(s) known to git.

引用論點

git commit -m "${comment}"

暫無
暫無

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

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