New question:
I can't do this (Error: line 2: [: ==: unary operator expected
):
if [ $(echo "") == "" ]
then
echo "Success!"
fi
But this works fine:
tmp=$(echo "")
if [ "$tmp" == "" ]
then
echo "Success!"
fi
Why?
Original question:
Is it possible to get the result of a command inside an if-statement?
I want to do something like this:
if [ $(echo "foo") == "foo" ]
then
echo "Success!"
fi
I currently use this work-around:
tmp=$(echo "foo")
if [ "$tmp" == "foo" ]
then
echo "Success!"
fi