I caught myself out; I couldn't log into root after I made a script and called it from ~/.bashrc.
~/.bashrc:
#... do stuff then run my script
source ~/myscript.sh
~/myscript.sh:
#!/bin/bash
if [myConditional]; then
exit
fi
# otherwise do stuff
What I had hoped was that when I log in as root, myscript.sh would be run, and if myConditional was true, myscript.sh would stop running any further commads, but would return to .bashrc and the user would still be logged in as root as usual. But instead, exit stopped me from being able to log in at all! It just returned me to a login prompt.
Is there another command I should be using besides exit? Obviously I could just extend the if statement by having an else statement and removing exit, but for educational purposes I'd like to know if there is a more appropriate approach. (Also partly because I want to avoid deeply nested if statements; it could be quite a large script)
sourceyour script - so the shell you areexiting from is the original onesource- if so, please edit to say what your goal is. What's in the "script"?