joseph
joseph

Reputation: 123

what is the difference between cmd1 & cmd2 and cmd1 && cmd2 in shell

can anybody tell me what is the difference between

cmd1 & cmd2 & ...

and

cmd1 && cmd2 && ....

in shell scripting. If they differ in execution may I know how each commands are actually get executed.

Upvotes: 2

Views: 2937

Answers (2)

Tharif
Tharif

Reputation: 13971

Assume there are cmd1 && cmd2. command2 will be executed if and only if command1 returned zero exit status.

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172438

cmd & means "run command in the background."

cmd1 && cmd2 means "run cmd1 and if it completes successfully, run cmd2 afterwards." So its like cmd2 will only be executed if cmd1 succeeds.

Upvotes: 5

Related Questions