0

I often "debug" bash scripts by opening them in the text editor and pasting them to the console, not line by line but "logical unit by logical unit".

Sometimes I then have these constructs:

if [ ! -f $inputFile ]; then
    echo "You must specify an existing file, milord!"
    exit 5
fi

However, pasting that to the console (without a valid $inputFile of course) immediately closes my console.

Is there any way to circumvent that?

Bowi
  • 1,378
  • 19
  • 33
  • 1
    [trap](https://tldp.org/LDP/Bash-Beginners-Guide/html/sect_12_02.html) – 0stone0 Oct 29 '20 at 15:10
  • Maybe this could help you: [how to trap errors inside the if statement](https://stackoverflow.com/questions/13103701/how-to-trap-errors-inside-the-if-statement) – 0stone0 Oct 29 '20 at 15:15

1 Answers1

2

One hack you could try would be to just make exit an alias:

alias exit='echo exiting...'

Your sample code now will just print exiting... and move on.

When you're done with your debugging session, you need to just:

unalias exit
Costi Ciudatu
  • 37,042
  • 7
  • 56
  • 92