【问题标题】:hooks/post-receive: Syntax error: "(" unexpected (expecting "done")挂钩/接收后:语法错误:“(”意外(预期“完成”)
【发布时间】:2013-02-11 21:59:33
【问题描述】:

我正在用 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 服务器时,我收到以下消息:

remote: hooks/post-receive: 10: hooks/post-receive: Syntax error: "(" unexpected (expecting "done")

当我尝试在命令行中运行它时,脚本可以正常工作而没有此消息。

有什么想法吗?

谢谢,

埃利亚希夫

【问题讨论】:

  • 那么files_to_notify=( $files_to_notify )应该做什么?

标签: git bash


【解决方案1】:

两种可能:

  1. #!/usr/bin/env bash 添加到脚本的顶部,以确保脚本由bash 而不是sh 运行,因为您使用的是数组,bash 扩展名。

    李>
  2. 停止使用数组,因为您不会以任何无法用简单的空格分隔字符串轻松替换的方式使用它。这就是您最初构建数组的方式。

【讨论】:

    猜你喜欢
    • 2016-06-04
    • 1970-01-01
    • 2018-05-29
    • 2016-05-16
    • 1970-01-01
    • 2014-02-18
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    相关资源
    最近更新 更多