我正在 GIT 中编写接收后脚本。
我附上了它的最小版本,但也失败了:
generate_email()
{
for user in $(git config --get-all notifications.users); do
unset files_to_notify
for filter in $(git config --get-all notifications.$user); do
files_to_notify=" $files_to_notify $(git diff-tree --no-commit-id \
--name-only -r $newrev | grep $filter) "
done
files_to_notify=( $files_to_notify )
if [ -n "$files_to_notify" ]; then
echo ${files_to_notify[*]}
fi
done
}
while read oldrev newrev refname
do
generate_email $oldrev $newrev $refname
done
当我尝试推送到 git 服务器以调用此脚本时,我收到以下消息:
远程:hooks/post-receive:10:hooks/post-receive:语法错误:“(”意外(期望“完成”)
当我尝试在命令行中运行它时,脚本可以正常工作而不会出现此消息。
有什么想法吗?
谢谢
埃利亚希夫
最佳答案
两种可能性:
将
#!/usr/bin/env bash
添加到脚本顶部,以确保脚本由bash
运行,而不是由sh 运行
,因为您使用数组,所以是bash
扩展。停止使用该数组,因为您不会以任何无法轻松用简单的空格分隔字符串替换的方式使用它。这就是您首先构建数组的方式。
关于git - Hook /接收后 : Syntax error: "(" unexpected (expecting "done"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14808114/