I would like to test a Bash function’s return value in an if statement like this:
if [[ func arg ]] ; then …
But I get error messages like: conditional binary operator expected.
What is the right way to do this?
Is it the following?
if [[ $(func arg) ]] ; then ...
If it was the exit code and not the result, you could just use
If you cannot make the function return a proper exit code (with
return N), and you have to use string results, use Alex Gitelman’s answer.$ help if: