I would like to use the return value of a bash function in a 'if not' statement. The following is an example script:
#!/bin/bash
function myfunction () {
if [ $1 = "one" ]; then
return 1
elif [ $1 = "two" ]; then
return 2
else
return 0
fi
}
if myfunction "two"; then
# just using echo as an example here
echo yep $?
else
# just using echo as an example here
echo nope $?
fi
Is there a way to modify the part 'if myfunction "two"' in a way that this script echoes 'yep 2'? I can only figure out this ugly way. How can can I solve this a better way?