Shell script prevent switching to other shell or escape from it

xendi asked:

If in my automation script, I need to do something like install oh-my-zsh, I will have a .sh script like this:


runuser -l user -c 'sh -c "$(curl -fsSL"'

This works and will install oh-my-zsh as I expect but it then puts the session into a zsh shell. If I add the command exit to the end of the script, it does nothing.

How can I either disallow switching to zsh (Or any other shell) or exit from it in my script?

My answer:

If you actually look at this script you will see that, as the last thing it does, it calls:

    exec zsh -l

Just before that, you will see that it checks to see if the RUNZSH variable is set to no. If so, then it will simply exit without going into the shell.

So all you need to do is pass the environment variable RUNZSH=no to the command.

The comments at the top of the script contain other variables you can set and command line options you can use.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.