I'm having a hard time getting the return value from a script. The script that is giving me trouble is
second.sh below. But there's an interaction present with a script called
first.sh, and that interaction seems to be the source of the trouble.
The first script is a test script and drives the second script. It needs the second script to set a cross-compile environment (hence the reason for a leading dot). The first script then invokes
make with various variables set, like
# first.sh . ./second.sh arg1 if [ "$?" -eq "0" ]; then make ... fi . ./second.sh arg2 if [ "$?" -eq "0" ]; then make ... fi . ./second.sh arg3 if [ "$?" -eq "0" ]; then make ... fi
The second script is usually run stand-alone by the user, and it's quite involved because it's detecting platforms, architectures and other miscellaneous features. It sets various variables, like
CXXFLAGS used by
make in the first script.
# second.sh ... # if success, return 0 exit 0 ... # if failure, return non-0 exit 1
The problem I am having is the call to
second.sh kills the terminal, so
first.sh is stopped dead in its tracks. A similar problem occurs when the user runs it stand alone.
When I attempt to change the second script to:
# second.sh ... # if success, return 0 return 0 # else for failure, return non-0 return 1
second.sh always fails, even with
How do I add a return code that does not kill the terminal under Bash?
To date, I've been running without the first test script, so the second script does not need to return success/failure. But I'm trying to automate testing, so I really need to be able to get a return code