Enrollments Open for Advanced Certification Courses on Data Science, ML & AI by E&ICT Academy IIT Roorkee
Apply NowSay, you want to execute a command only if another command is successful then you use &&
.
And if you want a command to be executed if another command has failed, you use ||
.
Create a file tea_ready
:
touch tea_ready
The following command would print "Tea is ready" if tea_ready
file exists:
ls -l tea_ready && echo "Tea is ready"
Delete the file tea_ready
:
rm tea_ready
Check the command from #2 again:
ls -l tea_ready && echo "Tea is ready"
The following will print "Tea is not ready":
ls -l tea_ready || echo "Tea is not ready"
You can use brackets to avoid confusion:
(ls -l tea_ready && echo "Tea is ready") || echo "Tea is not ready"
No hints are availble for this assesment
Answer is not availble for this assesment
Loading comments...