I have a function that returns a bunch of exit codes, say func1, and in my code I'm trying to execute that function in an if statement. This is the closest I could get.
f1call=`func1 $arg1 $arg2`
if [[ "$f1call" = "0" ]]; then
...
fi
When I run the script the function never gets called. What's the right way to do this?
Here are some other basic questions that I need answered too:
-When do we use double-brackets vs. single-brackets for the if-statement expression?
-Is the exit code that's being returned an integer or string? I ask this because I'm wondering if it should be "[[ $f1call = 0 ]]" as opposed to what I have up there.
func1()
{
.....do stuff
#echo "$EXIT_CODE"
return $EXIT_CODE
}
if func1 $arg1 $arg2
then
# func1 : succes (exit status 0)
else
# func1 : error
fi
func1 $arg1 $arg2
if [ $? -eq 0 ]
then
# func1 : succes (exit status 0)
else
# func1 : error
fi
#! /usr/bin/ksh
function abc {
echo "inside the function "
ty=1
exit $ty
}
echo "before the function abc"
val=`abc`
echo "val is $val"
echo "after the function abc"
exit 0
>output
before the function abc
val is inside the function
after the function abc