简体   繁体   English

在 Bash 脚本中,函数的第二个参数未按预期处理

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

Trying to combine git - add/commit/push in one fuction.尝试结合 git - 在一个功能中添加/提交/推送。

gitacp testfile/testfile.py "testing" works okay. gitacp testfile/testfile.py“测试”工作正常。

gitacp testfile/testfile.py "testing this" results in this error. gitacp testfile/testfile.py "testing this" 导致这个错误。 error: pathspec 'this' did not match any file(s) known to git.错误:pathspec 'this' 与 git 已知的任何文件都不匹配。

From some reason the set of strings in the second argument is not getting processed correctly.由于某种原因,第二个参数中的字符串集没有得到正确处理。

# 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