#!/bin/bash
function fun_call
{
yn=$1
return $yn
}
#here calling function as and sending arg 0
if fun_call "0" ; then
echo "true";
else
echo "false";
fi
---------------------
output is --- true
2)
#!/bin/bash
function fun_call
{
yn=$1
return $yn
}
#here calling function as and sending arg 1
if fun_call "1" ; then
echo "true";
else
echo "false";
fi
---------------------
output will -- false
3)
#!/bin/bash
function fun_call
{
#make it 0 other time
yn=1
return $yn
}
#here calling function as without argument
if fun_call ; then
echo "true";
else
echo "false";
fi
---------------------
if return 1 output is false
if return 0 output is true
************
Better to use like this
#!/bin/bash
function fun_call
{
#make it 0 other time
yn=1
return $yn
}
fun_call
st=$(echo "$? < 1" | bc)
if [ $st -eq 0 ] ; then
echo "true";
else
echo "false";
fi
#compare return using the bc and store in a string and work according to your logic
No comments:
Post a Comment