Reputation: 191
How do you do this? What I'm thinking is like this.. also, do I need to use fi and done? or only one of them
if[mv 1.txt > 2.txt == '0']
then
echo "Success"
else
echo "Failure"
fi
done
Upvotes: 3
Views: 1128
Reputation: 743
if mv 1.txt 2.txt
then
echo Success
else
echo Failure
fi
if
takes a command as its argument and executes the then
clause if the command ran successfully, or the else
clause if there was an error. Interestingly, once upon a time, [
was a command that evaluated the conditions you handed to it, and it is probably still available on your system -- check out /usr/bin/[
.
If you don't have a do
statement, you don't need a done
statement. fi
is required as the final statement of an if
command.
Upvotes: 1
Reputation: 785276
In BASH only this would suffice:
mv 1.txt 2.txt && echo "Success" || echo "Failure"
However if you want to use traditional if/fi
then use
if mv 1.txt 2.txt
then
echo "Success"
else
echo "Failure"
fi
Upvotes: 3