top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Explain "Exit Status" for a shell script ?

+1 vote
734 views
Explain "Exit Status" for a shell script ?
posted Jun 19, 2014 by Madhavi Latha

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

0 votes

exit 0; it means everything went OK. but if your program detects an error and decides to abort, you would use exit(1). Or you might use exit(1), exit(2), etc, with each exit code meaning some specific error.

answer Jun 19, 2014 by Amit Kumar Pandey
0 votes

Whenever any program completes execution under the Unix system, it returns an exit status back to the system. This status is a number that usually indicates whether the program successfully ran. By convention, an exit status of zero indicates that a program succeeded, and nonzero indicates that it failed. Failures can be caused by invalid arguments passed to the program, or by an error condition detected by the program. For example, the cp command returns a nonzero exit status if the copy fails for some reason (for example, if it can't create the destination file), or if the arguments aren't correctly specified (for example, wrong number of arguments, or more than two arguments and the last one isn't a directory). In the case of grep, an exit status of zero (success) is returned if it finds the specified pattern in at least one of the files; a nonzero value is returned if it can't find the pattern or if an error occurs (the arguments aren't correctly specified, or it can't open one of the files).

answer Jun 20, 2014 by Chahat Sharma
Similar Questions
0 votes
+2 votes

I am using below script to validate IPV6 address but this script also pass invalid IP such as empty string, name etc.

if [[ "$IPv6ADDR"=~"^:?([a-fA-F0-9]{1,4}(:|.)?){0,8}(:|::)?([a-fA-F0-9]{1,4}(:|.)?){0,8}$" ]]; then
  echo "valid ipv6 addr"
  break;
else
  echo "Invalid IP Address"
  break;
fi

Can someone identify what's wrong in the regex, Please?

+1 vote

I have some unique requirement, where I need to do something like this -
1. My script takes the argument as file name which is absolute filename.
2. I need to separate the filename and directory from this absolute file name for the further processing.

Any suggestions -

...