0

I'm trying to use Docker to run a shell script. Here is my Dockerfile:

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

However, when I try to run it, I get the following error:

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

This is what I have in 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 ###
...

The script works fine when I run it without using Docker. Any idea what might be causing this error?

  • Looks like you're using array syntax. That requires bash; it doesn't work with sh. – Charles Duffy Oct 18 '22 at 16:12
  • (also, you're using array syntax _badly_; see [BashPitfalls #50](https://mywiki.wooledge.org/BashPitfalls#hosts.3D.28_.24.28aws_.2BICY.29_.29) -- use `readarray`, `mapfile`, or `read -a` instead of word-splitting for more reliable behavior) – Charles Duffy Oct 18 '22 at 16:12
  • (perhaps on your "real" system sh is a symlink to bash; it still provides fewer features than real not-in-compatibility-mode bash when run under the sh name, but more than dash, ash, or otherwise baseline POSIX sh) – Charles Duffy Oct 18 '22 at 16:14

1 Answers1

0

FROM alpine doesn't give you a copy of bash, or any other shell with array support.

If you want to use arrays, you need to install and use a shell that supports them.

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441