• Post Reply Bookmark Topic Watch Topic
  • New Topic

exit command  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


If a is greater than b then exit with 1. What is the use of exit #? ?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What does the man pages say when the "exit" command is called with no parameters? Isn't "exit" the same as "exit 0"? And based on the program, isn't it obvious that it will be called when a is not greater than b?

Henry
 
Andrew Polansky
Ranch Hand
Posts: 310
18
Linux MS IE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This code wouldn't execute, but I get the idea.

In such case, if B would be bigger than A, the script would return 0. But not exactly because "exit" returns 0 by default.

The "exit" command executed without an argument is equivalent to "exit $?" - it will return exit value of the lastly executed command. The "$?" by default is equal to value of EXIT_SUCCESS (for Linux it's 0), therefore in this case "exit" will return 0.

A few experiments showing the behavior mentioned above.
In the examples I am using "tar" with random arguments to provoke a non-zero exit value. The stderr is routed to /dev/null to remove error messages from the screen.



 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!