0

I have shell script with certain commands being executed on alpine docker image. currently, it uses /bin/sh shell to execute all commands.

the issue is , in the script, there is while loop which has counter. below code

i=0
cnt=15
while [ "$a" == "b" ] && [ "$i" == 15 ]
do 
  echo " Waiting for ..."
  sleep 2s
  ((i=i+1))
  ((cnt=cnt-1))
done

issue is on the line ((cnt=cnt-1)) , getting following error

sh: was: unknown operand /bin/sh: exit: line 178: Illegal number: -1

I was thinking of moving from /bin/sh to /bin/bash , can this be solution. if yes , how I can set the default shell as bash before executing the script. OR using the current shell only , how to resolve this counter issue.

please suggest

EDIT 1 the output of : ls -l /bin/sh

$ ls -l /bin/sh
lrwxrwxrwx    1 root     root            12 Nov 12 09:18 /bin/sh -> /bin/busybox
user2315104
  • 2,378
  • 7
  • 35
  • 54
  • `it uses /bin/sh` what is "it"? How exactly do you execute the script? What is the shebang in the file? – KamilCuk Dec 31 '21 at 12:37
  • executing script through gitlab ci yaml file. I haven't set any shebang line . Do you suggest setting shebang line ? – user2315104 Dec 31 '21 at 12:45
  • That's how you usually do it, yes. – tripleee Dec 31 '21 at 12:58
  • 2
    `executing script through gitlab ci yaml file` Please _do not omit such important details_. Still, how exactly do you execute the script? Do you do `script: - i=0 - snt=15 -while ... etc` or you do `script: - ./yourscript` or you do `script: - /bin/sh ./yourscript`? Is the script executable? Please post `gitlab-ci.yml` file. What is the shebang in the file? What image exactly are you using? `:latest`? Have you installed bash? If you intend to use bash, why not use image with bash, instead of alpine? – KamilCuk Dec 31 '21 at 13:02
  • Does Alpine Linux even include bash (by default, that is)? – Gordon Davisson Dec 31 '21 at 22:51

0 Answers0