jeudi 29 janvier 2015

How do I use a function return as a condition of an if else then shortcut?


There are instances where a function needs to execute and return to the caller and this works for me.



if tst; then
echo "success"
else
echo "failure
fi

function tst () {
return 0;
}


However, I can't seem to be able to do it using shortcut syntax. I've tried many combinations of the following statement including testing if [[ tst = true ]] or if it = "0" but I haven't been able to figure it out.



[[ tst ]] && echo "success" || echo "failure"


What is the proper way to test the function in the if condition using bash shortcut syntax?



Aucun commentaire:

Enregistrer un commentaire