Friday, August 21, 2015

how to get exit status or exit code or return code of a coommand after it is executed

exit status or exit code or return code are all have the same meaning, to get it we use command, echo $?

I- what are the meaning for every exit status

0 Success
1 General errors
2 Misuse of shell built-ins
126 Command invoked cannot execute
127 Command not found
128 Invalid argument to exit Fatal error signal “n”
130 Script terminated by Ctrl-C 255 Exit status out of range

II- example

$ ls
myfile1  myfile2  myfile3  myfile4
$ echo $?

0

$ anycommandthatisnotexist
anycommandthatisnotexist: command not found
$ echo $?
127

$yes these text will be displayed
these text will be displayed
$echo $?
130

No comments:

Post a Comment