在Docker中运行shell脚本时出错-语法错误:意外的“(“(应为“}”)[重复]

dzjeubhm  于 2022-11-16  发布在  Shell
关注(0)|答案(1)|浏览(103)

此问题在此处已有答案

Docker: How to use bash with an Alpine based docker image?(6个答案)
28天前关闭。
我正在尝试使用Docker运行shell脚本。以下是我的Docker文件:

FROM alpine
COPY . .
RUN chmod +x ./scripts/sanity-checks.sh
ENTRYPOINT ["./scripts/sanity-checks.sh"]

但是,当我尝试运行它时,我得到以下错误:

./scripts/sanity-checks.sh: scripts/util.sh: line 225: syntax error: unexpected "(" (expecting "}")

这是我在www.example.com上看到的内容util.sh:

...  
# delete the lines between and including 2 comment lines, or the comment lines themselves only
    delete_lines_for_file() {
      file_name=$1
      delete_string_start=$2
      delete_string_end=$3
      delete_comments_only=$4
      # find the start and end lines where we want to delete blocks of code
      line_num_start=$(grep -n "$delete_string_start" $file_name | awk -F  ":" '{print $1}')
      line_num_end=$(grep -n "$delete_string_end" $file_name | awk -F  ":" '{print $1}')
      line_start_arr=($line_num_start) ### LINE 225 ###
...

当我在不使用Docker的情况下运行脚本时,它工作正常。知道是什么原因导致了这个错误吗?

nszi6y05

nszi6y051#

FROM alpine不提供bash的副本,也不提供任何其他支持数组的shell。
如果要使用阵列,则需要安装和使用支持阵列的shell。

相关问题