I have a BASH script that calls a function, which calls other functions:
#!/bin/bash
function foo
{
function bar
{
# do something
}
bar
}
foo
How can I return from bar
directly to the main function? The case is that bar
handles user input and if it receives a negative answer, it must return to the main function, otherwise it has to return to foo
.
Returning to foo
is not a problem with a simple return
statement. For the other, I tried this (which actually works):
#!/bin/bash
function foo
{
function bar
{
if [negative] # abstract statement
then return 1
else return 0
fi
}
! bar && return
}
foo
But since I have functions like foo
spread across the whole project (bar
is defined in a header file), is there a way that only requires modification to bar
? The project is ~2k lines long and consists of several files, it would be much easier that way if there's a solution.
goto
, which doesn't exist in bash as far as I know.goto
unfortunately.