0

I am trying to set up my environment using a bash script. One of the things that I need to do in the bash script is to restart bash, which I use exec bash for. Is there a way to have the script continue after the exec bash command? Currently it does not run any command after that command.

Ben Rei
  • 73
  • 1
    Do you mean you want to execute command after command? like; in bash: $ exec bash && echo command2 goes here ? – Jane Oct 09 '20 at 17:37
  • 2
    Restarting bash means to me that the old bash process is terminated and only the new bash is running. Do you want the old bash process to continue? Or do you want the new bash to perform the commands, that you want to run after it has been started? – sudodus Oct 09 '20 at 17:46
  • I'd want the new bash to perform the commands – Ben Rei Oct 09 '20 at 17:50
  • 1
    I will try to paraphrase @sudodus's comment. exec bash will substitute the current PID with a new bash shell. So you need something like exec my_next_script.sh. In this scenario this answer could be adpted according to your needs. However, I suppose you just need to source some environment file, like . ~/.bashrc (or source ~/.bashrc). – pa4080 Oct 09 '20 at 18:01
  • 2
    Perhaps take a step back and explain why you need to restart bash part way through a script (just so we can make sure it's not an XY problem ) – steeldriver Oct 09 '20 at 18:16
  • Explain what you are trying to do. The how is wrong, but if we know what, then we can probably help. – ctrl-alt-delor Oct 09 '20 at 18:16
  • I am restarting bash after I run the command conda init to have anaconda start in my bash shell (because it does not start automatically on the server that I am on) – Ben Rei Oct 09 '20 at 20:49

0 Answers0