Linked Questions
21 questions linked to/from Exit Shell Script Based on Process Exit Code
628 votes
10 answers
275k views
Aborting a shell script if any command returns a non-zero value
I have a Bash shell script that invokes a number of commands. I would like to have the shell script automatically exit with a return value of 1 if any of the commands return a non-zero value. Is this ...
1 vote
2 answers
7k views
Catch bash exit code in if statement [duplicate]
If I do a simple test of exit codes directly with single commands: [user@localhost ~]$ date Tue Sep 8 14:00:11 CEST 2020 [user@localhost ~]$ echo $? 0 [user@localhost ~]$ dat bash: dat: command not ...
2 votes
3 answers
1k views
Linux - Capture exit code of a ruby script [duplicate]
I have a simple ruby script which uses the abort function to exit with a non-zero exit code #!/usr/bin/env ruby puts "I ran" abort "Exiting" How can I capture the exit code when I execute this ...
1190 votes
12 answers
803k views
What does 'set -e' mean in a Bash script?
I'm studying the content of this preinst file that the script executes before that package is unpacked from its Debian archive (.deb) file. The script has the following code: #!/bin/bash set -e # ...
31 votes
5 answers
66k views
What does "$?" give us exactly in a shell script? [duplicate]
I saw the code written somewhere online, and I wanted to know what exactly does "$?" do/give us. Googling did not help. Here's the code I saw it in: #!/bin/sh ping -c 2 localhost if [ $? != 0 ] ; ...
19 votes
6 answers
31k views
Shell status codes in make
I use a Makefile (with GNU make running under Linux) to automate my grunt work when refactoring a Python script. The script creates an output file, and I want to make sure that the output file remains ...
39 votes
2 answers
15k views
Why is testing "$?" to see if a command succeeded or not, an anti-pattern?
I see here that testing whether $? is zero (success) or something else (failure) is an anti-pattern, but I have not been able to find this anywhere else. Sticking to the definition of anti-pattern of ...
25 votes
3 answers
11k views
NodeJS Managed Hostings vs VPS [closed]
There are a bunch of managed cloud based hosting services for nodejs out there which seem relatively new and some still in Beta. Yet another path to host a nodejs app is setting up a stack on a VPS ...
14 votes
2 answers
22k views
Running a Python script within shell script - Check status
Within my shell script I run this command: python script.py I was wondering, as a two part question: How can I program my python script to pass a status back to the shell script that ran it depending ...
26 votes
1 answer
6k views
Exit code of command substitution in bash local variable assignment [duplicate]
How can I check the exit code of a command substitution in bash if the assignment is to a local variable in a function? Please see the following examples. The second one is where I want to check the ...
6 votes
1 answer
9k views
exec maven plugin: exit code
I am having the following plugin to run a .sh script: <plugin> <artifactId>exec-maven-plugin</artifactId> <groupId>org.codehaus.mojo</groupId> <executions> ...
0 votes
2 answers
2k views
View exit code of a program (After the program exited)
Lets say a program that outputs a zero in case of success, or 1 in case of failure, like this: main () { if (task_success()) return 0; else return 1; } Similar with Python, if ...
0 votes
2 answers
3k views
Return value of ping [duplicate]
I have done a file named hosts.txt which includes some websites, to test the ping on each website with a script. What I want to do with my script is I want to loop through each line that includes ...
2 votes
1 answer
2k views
How to write a Git pre-commit hook that prevents committing of an Android project if the test project fails?
Given that I in my workspace I have an android project MyAndroidProject and my tests project MyAndroidProjectTests directories how could I write a pre-commit git hook that will run the tests in the ...
1 vote
1 answer
2k views
run 2 rsync commands and print the output to a log file
I'm new to scripting and would like to understand how to print out the variables based on boolean logic. #!/bin/bash # set variables WEBAPPS_YES="Successfully synced webapps folder" WEBAPPS_NO="...