0

I have some confusion in how following expression works.

cc file_name.c  && ./a.out 

When filename.c gets compiled successfully , its exist status would be 0 (zero). So as per logical && operation , second expression ( ./a.out ) not suppose to be executed. But it still works and gives me result. How it works ?

Thanks

Pavunkumar
  • 5,147
  • 14
  • 43
  • 69

2 Answers2

2

0 means success in the shell. It's not the same as in C. From the bash man page:

AND and OR lists are sequences of one of more pipelines separated by the && and ││ control operators, respectively. AND and OR lists are executed with left associativity. An AND list has the form

command1 && command2

command2 is executed if, and only if, command1 returns an exit status of zero.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
1

When executing shell commands, a return value of 0 means the command was executed successfully. Non-zero value means there was an error processing the command. So, if previous command was a success it would proceed to the next command, else abort.

devang
  • 5,376
  • 7
  • 34
  • 49