commit-msg 钩子给出“[[: not found”错误

commit-msg hook gives "[[: not found" error

提问人:Thundercleez 提问时间:8/10/2023 更新时间:8/10/2023 访问量:56

问:

我的 .git/hooks/commit-msg 文件看起来像

#!/bin/sh
COMMIT_MSG_FILE=$1
comm_msg=$(head -l $COMMIT_MSG_FILE)
if [[ $comm_msg =~ ^TASKID-[\d]+ ]]; then
  exit 0
else
  echo "Commit message must start with task id." >&2
  exit 1
fi

但是当我跑步时

git commit -m "test commit"

我收到错误“.git/hooks/commit-msg: 4: .git/hooks/commit-msg: [[: not found.我看不出我的语法有什么问题。可能导致此错误的原因是什么?

git-commit 预提交钩

评论

1赞 Mat 8/10/2023
这回答了你的问题吗?Bash 语法错误:“[[: 未找到”
0赞 John Bayko 8/10/2023
顺便说一句,您可能希望将任何可以扩展的内容(例如或参数)放在引号中,这样它们就不会被解释为正在执行的命令行的一部分(例如,if 或具有空格或有效的 shell 运算符)。$*COMMIT_MSG_FILEcomm_msg
0赞 Thundercleez 8/10/2023
啊,#!/bin/bash 而不是 sh。我错过了微妙的差异!

答: 暂无答案