运行Shell脚本时替换错误

时间:2018-06-30 21:08:45

标签: bash docker

当我尝试为docker运行初始化和运行脚本时,它给我一个错误:

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

两个文件编写如下:

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

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

当我进行搜索时,大多数答案是在顶部添加#!/bin/bash,但这不是解决方案。

0 个答案:

没有答案