0

When I try to run a init and run script for my docker, it gives me an error:

docker_init.sh: 5: docker_init.sh: Bad substitution

Two files are written as follows:

init.sh

#!/bin/bash
#
DOCKER_PROCESS=$(docker ps | head -1)

if [ ${DOCKER_PROCESS:0:9} == "CONTAINER" ]
then
    echo "Docker is up!"

    echo "docker stop all"
    docker stop $(docker ps -q -a)

    echo "docker rm all"
    docker rm $(docker ps -q -a)

    echo "docker rmi all"
    docker rmi $(docker images -q)

    echo "docker build backend"
    docker build -t backend .
fi

###############################

run.sh

#!/bin/bash

DOCKER_PROCESS=$(docker ps | head -1)

if [ ${DOCKER_PROCESS:0:9} == "CONTAINER" ]
then
    echo "Docker is up!"

    echo "docker run -p 5000:5000 -it backend"
    docker run -p 5000:5000 -it backend 
fi

###############################

When I searched this up, most answers told be to add #!/bin/bash on the top, but that was not the solution.

Dawn17
  • 7,825
  • 16
  • 57
  • 118
  • If you are runining the script with `sh init.sh` it doesn't matter at all what the first line says. – tripleee Jun 30 '18 at 21:12
  • Is there "Why does my bash script fail when I run `sh myscript`" duplicate? All the ones I can find are mostly incidental and not good candidates for deduping – that other guy Jun 30 '18 at 21:14
  • The bashism can easily be avoided with something like `case $DOCKER_PROCESS in "CONTAINER"*) ...;; esac` – tripleee Jun 30 '18 at 21:24

0 Answers0