If I run this:
#!/usr/bin/env bash
simple_return_zero(){
return 0;
}
simple_return_one(){
return 1;
}
if [ simple_return_zero ]; then
echo "we have 0000";
fi
if [ ! simple_return_zero ]; then
echo "we have not 00000";
fi
if [ simple_return_one ]; then
echo "we have 11111";
fi
if [ ! simple_return_one ]; then
echo "we have not 11111";
fi
I get:
we have 0000
we have 11111
I know the above is the wrong code to use, I think this is the right way to do it:
if simple_return_zero; then
echo "we have 0000";
fi
if ! simple_return_zero; then
echo "we have not 00000";
fi
if simple_return_one; then
echo "we have 11111";
fi
if ! simple_return_one; then
echo "we have not 11111";
fi
and now we get something more expected:
we have 0000
we have not 11111
My question is - why doesn't the test command ( [ ] ) work in this case? Doesn't the test command check for exit codes / return codes???