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)
source
your script - so the shell you areexit
ing from is the original one – steeldriver Sep 26 '16 at 00:58source
- if so, please [edit] to say what your goal is. What's in the "script"? – Michael Homer Sep 26 '16 at 01:02