Linux Combining

Education is not limited to just classrooms. It can be gained anytime, anywhere... - Ravi Ranjan (M.Tech-NIT)

Combining && and ||

The combination of logical AND and logical OR is used to write an if then else structure in the command line.

If first condition (if) will be fulfilled then command line execution stops there.

But if first condition is a failure, then second one (else) executes.


cd Desktop && file jtp.txt || echo successful.

Linux Combining && and ||

Look at the above snapshot, from command "cd Desktop && file jtp.txt || echo successful.", first (if) command (cd Desktop && file jtp.txt) is successfully executed and hence command line execution stops.

But second time, 'if' part execution is unsuccessful, hence 'else' part will be executed.