Question

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
Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top