0

How do you get your .bashrc file to exit on the first error in the script without inheriting the errexit setting into the interactive bash shell?

    # my .bashrc
    set -o errexit 

    # do something bad
    sdgjsghsdjksjkghsdfg sdghsdfkjhgskg sgsdfgs 

I thought I was clever by setting "errexit" in my .bashrc so it would exit on the first error.

...But, It doesn't work! ... because after .bashrc exits, your shell window disappears like its crashing every time an error occurs on the command line. Just typing "grep" without any arguments causes bash shell and terminal window to close....

how to get .bashrc to exit on the first error without undesirable effects of blowing up your terminal window on every error you type on the command line?

pico
  • 1,660
  • 4
  • 22
  • 52
  • 2
    If you need to debug your `.bashrc` use `set -ox` and read https://stackoverflow.com/questions/951336/how-to-debug-a-bash-script. `.bashrc` should not fail. – Dudi Boy May 30 '19 at 16:23
  • 2
    .bashrc is being executed by your shell; if it exits, it *exits your shell*. That's what `exit` does. It sounds like you want to `return` on error (which would stop running commands from .bashrc, but leave the shell itself running), but you don't really want that -- as @DudiBoy said, you want your .bashrc to *work*. – Gordon Davisson May 30 '19 at 17:09

0 Answers0