【问题标题】:In Bash Script Second Argument to Function is not Processed as Expected在 Bash 脚本中,函数的第二个参数未按预期处理
【发布时间】:2019-01-24 17:14:34
【问题描述】:

尝试将 git - add/commit/push 合并到一个功能中。

gitacp testfile/testfile.py "testing" 工作正常。

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.

【问题讨论】:

  • 问题是缺少引号。使用Shellcheck 来识别此类问题以及许多其他问题。

标签: linux bash git


【解决方案1】:

引用论据

git commit -m "${comment}"

【讨论】:

  • 工作。谢谢。
猜你喜欢
  • 1970-01-01
  • 2012-02-21
  • 2013-04-20
  • 2019-03-20
  • 2020-11-17
  • 1970-01-01
  • 2014-07-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多