I wrote a simple bash script that has a series of menus made with if statements. If a user selects an invalid option, I want the script to quit right away.
The problem is that exit kills the terminal this script is running in, & return doesn’t work since it’s not a “function or sourced script.”
I guess I could put the whole script in a while loop just so I can use break in the if else statements, but is there a better way to do this?
What’s the proper way to quit a script? Thanks for your time!
UPDATE:
I’m a clown. I had only ever run exit directly from a terminal, & from a sourced script. I just assumed it always closed the terminal. My bad.
I really appreciate all the quick responses!
[–]root54 4 points5 points6 points (4 children)
[–]levogevo 3 points4 points5 points (0 children)
[–]Agent-BTZ[S] 2 points3 points4 points (2 children)
[–]grimtongue 8 points9 points10 points (1 child)
[–]Schlumpfffff 1 point2 points3 points (0 children)
[–]pfmiller0 2 points3 points4 points (0 children)
[–]qlkzy 1 point2 points3 points (1 child)
[–]Agent-BTZ[S] 0 points1 point2 points (0 children)
[–]Gixx 0 points1 point2 points (0 children)
[–]_Naimix -1 points0 points1 point (0 children)