Okay, for reasons related to sourcing a script from another script, I've had to put my main loop into a function, and from there I call other functions. My problem then is exiting from deep within the function call stack.
I used to simply call exit, and that would accomplish what I needed. But now, exit simply exits the function, and not the script. After a little experimentation, I found I could do the following:
And that accomplished the multi-level exit that I needed, but it doesn't allow me to return the correct error code to the user. It also will make it difficult to call this script from within another script, but that is not really a problem I care about at the moment. Any hints, this must be a common issue. I want the equivalent of C's exit behavior.
It definitely exits with status 2, not status 1. If, in asdf, I source a script that calls exit with status 3, the entire script exits with status 3. So, I suspect there are issues elsewhere in your code preventing it from calling exit properly -- perhaps it's being called in a subshell, behind braces or pipes? Or perhaps you're not getting the shell you want.
Last edited by Corona688; 06-11-2010 at 12:24 PM..
OK,
I know function has to be defined first - in sequence - before it can be used.
So the script has to be build "bottoms -up style, if you pardon my expression.
I am running into a problem reusing function and breaking the sequence.
It would be nice to be able to see the function... (10 Replies)
In the bash function below if the user selets "y" then the menu function is called and if they select "n" the move function is called. That all seems to work, my question is after the files are moved an echo,
line in bold is displayed and another function called backup is called. I am getting a... (1 Reply)
I'm trying to call some functions in the background so that I can multitask in this script. Not working so hot. The functions I call don't ever seem to get called. I'm doing it the exact same way in another script and it's working like a champ so I'm very confused. Here's a pretty simple repro:
... (7 Replies)
Hi,
I have parent script which is invoking multiple child scripts. I would want to kill all the child processes before the parent
process exit.
> cat ./parent
#!/bin/ksh
while
do
. ./child arg1 &
if ; then
break
fi
done
Is there a way to get the process group id for all the child... (3 Replies)
I have a bash script with some functions as below and am wondering if I can use the variables declared in setup in the other functions and in the rest of the bash script.
setup(){
none=0; low=1; medium=2; high=3; debug=4
var1="red"
var2="fred"
}
create_basemap() {
... (7 Replies)
Hi all,
I'm trying to import some functions I have saved in a file named
functions.sh into a different script (protocol.sh). Can anybody show
me how to do this? I tried source functions.sh as I would do at the
terminal but source command cannot be found from within the script
protocol.sh.
... (2 Replies)
This script is called fuu;
#!/bin/bash
speak() {
case $1 in
1)echo one
;;
2)echo two
;;
3)echo three
;;
esac
}
speak
exit 0
when i run fuu 2 i expect "two" like... (2 Replies)
Hi,
How can i do the mathematical calculations in bash shell?
Are the mathematical functions available in bash shell?
Ex:
pow
ceil
floor
sqrt (5 Replies)
Hello all,
Problem.
----------
I'm trying to reassign a referenced variable passed to a 'local'
variable in a function but the local variable refuses to be assigned
the content of the referenced variable.
Any ideas would be appreciated.
Objective.
-----------
Eliminate all $VAR... (1 Reply)
Hi I am having the script which contains more functions. I want to exit the function if any failure. I tried with exit - the session itself is getting logged out. How can i fix this issue? (11 Replies)