Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Error running shell script in Docker – syntax error: unexpected "(" (expecting "}")

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

...  
# 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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading