简体   繁体   中英

The ‘exit' statement in a shell script running in a Docker container exits the script but also the container; Can I prevent exiting the container?

I want to run a Linux script in a Docker container and use the exit statement when I want to stop the script. Unfortunately I also exit than the Docker container. Is there a way to prevent exiting the container?

Here is the test code I'm using in its simplest form.

#!/bin/bash
function continue_exit {
        echo "Do you want step $1?"
select yn in "Yes" "No"; do
        case $yn in
           Yes ) break;;
           No ) exit;;
        esac
done
}

continue_exit "1"
echo "we continue"

Entering 1 runs the echo statement, entering 2 exits script AND container.

You have a typo in your script.

The last character (and another one) is not a simple double quote, but an unicode character:

$ echo '“' | od -c
0000000 342 200 234  \n

So replace it with " :

sed -i 's/“/"/g' script

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM