First of all: Using 'test' as a name for a function, variable, or script-file is not a good idea. This is because there is nearly always a program called 'test' installed in UN*X / Linux system as a part of the system.
So, in the scripts below I changed the name of your function to 'mytest'.
Two possible scripts for what you are trying to do. (but you mixed the two ways, which doesn't work) :
Code:
#!/bin/bash
function mytest()
{
echo "Function executed"
return 0
}
mytest # First call the function
if [ $? == "0" ] # Then check the code returned
then
echo "Success";
fi ## you forgot 'fi' here to end the 'if' statement.
exit 0 # Not needed, but "Good practice" in general
But since you wanted the "if"-statement only to executed if the function returns 0, the if statement can be simpler:
Code:
#!/bin/bash
function mytest()
{
echo "Function executed"
return 0
}
if mytest
then
echo "Success";
fi
exit 0