Questions tagged [exit-status]

Use this tag If your question revolves around determining or utilizing the exit status (return code) of a command. Common syntax involves the $? variable and the && and || symbols.

48
votes
4answers
61k views

Default exit code when process is terminated?

When a process is killed with a handle-able signal like SIGINT or SIGTERM but it does not handle the signal, what will be the exit code of the process? What about for unhandle-able signals like ...
5
votes
1answer
2k views

Linux kernel action upon init process exiting

Say I am writing my own init program running on a Linux kernel. What happens when my init program exits with return value 0 ? Additionally is the behaviour different if the return value is non-zero?
7
votes
2answers
2k views

How do I look up exit codes for applications?

I'm having difficulty locating a comprehensive up-to-date list of error codes from Bash. e.g.: $ udevadm info /dev/sdx; echo Exit code $? Unknown device, --name=, --path=, or absolute path in /dev/ ...
8
votes
2answers
1k views

How is the return status of a variable assignment determined?

I have seen constructs in scripts such as this: if somevar="$(somecommand 2>/dev/null)"; then ... fi Is this documented somewhere? How is the return status of a variable determined and how does ...
37
votes
4answers
11k views

What is the min and max values of exit codes in Linux?

What is the min and max values of the following exit codes in Linux: The exit code returned from a binary executable (for example: a C program). The exit code returned from a bash script (when ...
9
votes
5answers
35k views

How does one extract a command's exit status into a variable?

I started learning Bash a couple of days ago. I'm trying to obtain an exit status of grep expression into a variable like this: check=grep -ci 'text' file.sh and the output that I got is No ...
10
votes
2answers
493 views

Assignments are like commands with an exit status except when there's command substitution?

See the following examples and their outputs in POSIX shells: false;echo $? or false || echo 1: 1 false;foo="bar";echo $? or foo="bar" && echo 0: 0 foo=$(false);echo $? or foo=$(false) || ...
3
votes
3answers
7k views

What return/exit values can I use in bash functions/scripts?

I want to know what return values we can use that will not be mistaken by for ex. SIGINT? ex.: $sleep 10 $#hit ctrl+c $echo $? 130 so I know I must not use anything like return 130 or exit 130 so ...
2
votes
4answers
469 views

What exit modes exist in shell-scripting in general and in Bash in particular?

I know that in shell-scripting an "exit" usually means voluntarily or at least successfully terminating a session (or a process within a session) and that there are several different exit modes; the ...
10
votes
4answers
14k views

Bash script to detect the version control system by testing command return status

I am working on a bash script that I would like to work for several types of VCS. I am thinking of testing if a directory is a repo for a system by running a typical info command and checking the ...
6
votes
1answer
25k views

Return code for curl used in a command substitution

I've script as below :- (edited) httpUrl="http://www.nnin.com" rep=$(curl -v -X POST -d "UID=username&PWD=pass" $httpUrl) status=$? if [ "$?" -eq 0 ]; then echo "Success" exit $status ...
11
votes
2answers
947 views

How to make `local` capture the exit code?

In my project I have the following snippet: local output="$(bash "${1##*/}")" echo "$?" This always prints zero due to local, however, removing local causes the $? variable to behave correctly: ...
9
votes
2answers
18k views

Differences between inactive vs disabled and active vs enabled services

I am confused by the concept of enabled or active and disabled or inactive. Could someone explain it?
7
votes
3answers
178 views

Is there a way to get an process exit status after many more commands have been issued in linux?

If I have a lot of commands I've issued and I want the exit status of a process that exited say 100 commands ago. Is there a struct, file location, or variable in linux I can access all of exited ...
9
votes
1answer
533 views

Cause `less` to exit with a non-zero status code?

I would like to have the following command structure: command && check-status | less && followup-command This would pause the execution while the user interacted with less. How can ...
7
votes
2answers
2k views

make find fail when nothing was found

When find is invoked to find nothing, it still exits with code 0. Is there a way to make it return an exit code indicating failure when no file was found?
3
votes
1answer
2k views

Why is “Doing an exit 130 is not the same as dying of SIGINT”?

From Stéphane Chazelas's reply at https://unix.stackexchange.com/a/230568 Ideally, we'd want to report to our parent that we died of a SIGINT (so that if it's another bash script for instance, ...
1
vote
3answers
303 views

Difference between `exit;` and `exit $?;`

Is there any difference between these two commands: exec "$(dirname "$0")/suman-shell"; exit $?; and exec "$(dirname "$0")/suman-shell"; exit; is the $? redundant in the first case?
1
vote
1answer
5k views

Script handling systemd service's return code

I'm writing a systemd service which can be started or stopped using systemctl commands. However this program can also return with several return codes and I would like to handle those return codes. ...
0
votes
1answer
971 views

Return value error in bash scripts

I have bash script like this: rm ~/sqoop/"$TABLE"/* rmdir ~/sqoop/"$TABLE" return $? After execution this script it returns a value to next process but even though the script run successfully and ...