Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

4
votes
4answers
363 views

Bash - Execute two commands and get exit status 1 if first fails

In the case below, the report command must always be executed but I need to get an exit status 1 if the test command fails: test;report echo $? 0 How can I do it in a single bash line without ...
0
votes
2answers
48 views

Exit status of last command using PROMPT_COMMAND

I want to save the exit status of the last ran command (in a file, in a variable, it doesn't really matter), but this must be done automatically in an interactive shell, manually running something ...
1
vote
1answer
61 views

Exit status of chained commands

I want to run a potentially invalid command in a variable cmd. I can't afford to have it just fail me and retrieve the exit status. What I can try to do is pipe it to : and then I'll have a successful ...
1
vote
0answers
95 views

What does it mean when Duplicity exits with exit status 23?

I'm running Duplicity for backup of my desktop to a remote storage. Everything has been working fine, but now I see in my log that Duplicity has been exiting with exit status 23 for a couple of runs. ...
0
votes
3answers
67 views

Handle specific error in bash

As a part of my script, I want to publish package to nuget feed: dotnet nuget push package.1.2.3.nupkg --source "mysource" --api-key "mykey" The command may print error: 409 already contains version ...
1
vote
3answers
457 views

Remote Command executed via ssh does not return proper return code. Return error code is always “0”, even condition failed

I am not getting proper exit return code during execution of remote script on a Linux machine. This script is intended for checking whether a user exists or not. My Script is below :- #!/bin/bash ...
0
votes
2answers
60 views

Why echo$?' returns 0 even though 1 is expected? [closed]

For the following program, I get 0 for echo$? even though I expect 1. int main() { return 1; }
1
vote
1answer
2k views

lftp return code

I have written below code to get listing from a remote server. echo "set xfer:log yes" > batchfile.txt echo "set xfer:log-file Templogfile1.txt">> batchfile.txt echo "open -p $rport -u $...
0
votes
1answer
60 views

exit status from rsync command

When I am executing rysnc command the exit status is 0, even though the command throws an error (code 23). I want to use the exit status code to terminate the script when there are no files found but ...
7
votes
1answer
619 views

List of error messages available for a command in Unix

Is it possible to find out what error messages a command includes? For example I want to see the list of error messages that mkfs.ext3 command will print in different error situations. Shall I look ...
26
votes
1answer
990 views

Finding files for which a command fails

I would like to recursively find all the files for which a script which accepts a file as an argument returns a non-zero value. Any idea how to do this using 'find' or a similar tool?
4
votes
1answer
106 views

How to make `trap` know if the EXIT is after successful program finish or because of premature as an error or something

PROBLEM: I have a shell program that I have been writing but I can't find out how to make sure that trap is trapping for cleanup at the end or because of a error in some command, it cleans up either ...
3
votes
2answers
730 views

systemd status=127 for /usr/bin/install when trying to start MariaDB

I just upgraded my MariaDB installation to 10.2. When I now try to start the service, it tells me it failed an checking the status shows me this rather strange message: root@server # systemctl status ...
0
votes
0answers
40 views

How to enter and leave a man page in a script

I want to run a script that enters a man page and leaves it. Something like (in pseudo-code) $ man man q How can I do such a thing? Preferably the exit code will be 0. More generally how do I do ...
6
votes
2answers
13k views

What does gpg error code 2(GPG_ERR_UNKNOWN_PACKET) mean?

I am tasked to explain the variation of gpg errors that happened in one of my batch script. Currently when I perform gpg decrypt for a specified file it returns 2. The problem with this is when I ...
9
votes
2answers
17k 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?
2
votes
2answers
366 views

How to detect an error using process substitution

This question is similar to the following link, but focused on using the command line (bash shell). Using a simple example, when doing the following command: $ cat <(date); echo $? Fri Jul 7 21:...
3
votes
2answers
358 views

Why can't I get pgrep output right to variable on bash script?

I'm trying to make a script to either quit compton if it's running or start it if it's not running. I've read from man that it should exit 1 if process is found, so I've tried to make a script that ...
3
votes
2answers
911 views

Bash Script Function Return True-False

I want to query the function by returning the value. My codes are as follows; check(){ file=/root/Turkiye.txt local funkx=$1 while read line; do if [ "$line" == "$funkx" ] ...
0
votes
2answers
1k views

How to check for command exit code inside if statement

I'm trying to return a 0 exit code if a command exit with the a code 143 (timeout, from the "timeout command"), 1 otherwise. Due to external constraint (CI script), I have to start the command and do ...
0
votes
2answers
159 views

What is Linux exit status and list of all status

I'm trying to learn Linux bash scripting and I'm read through the articles in the http://tldp.org sites I saw some kind log clearing scripting I notice that something is used for as an exit status. I ...
0
votes
0answers
32 views

C++ script on Spark Cluster throws exit status 132

I'm trying to run a c++ program on spark cluster by using the rdd.pipe() operation but the executors throw: java.lang.IllegalStateException: Subprocess exited with status 132. The spark jar runs ...
4
votes
1answer
73 views

Display output of `time` only if command after `time` was successful

I want the output of the time command to be shown only if the command, which has been passed to time was successful. Something like this: ( time wget -pq --delete-after https://www.example.com ) 2>...
0
votes
0answers
51 views

Is it possible to “coax” arbitrary core *nix utilities into returning a non-zero exit status even when successful?

I am running bash scripts and executing bash commands on remote systems using Connectwise Automate (formerly LabTech). These systems are both Linux and MacOS. Connectwise Automate (CWA) has some ...
20
votes
5answers
3k views

What does typing a single exclamation mark do in Bash?

Bash uses exclamation marks for history expansions, as explained in the answers to this question (e.g. sudo !! runs the previous command-line with sudo). However, I can't find anywhere that explains ...
7
votes
3answers
164 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 ...
7
votes
3answers
2k views

Why does the exit status differ when running `systemctl start; systemctl is-active` and `systemctl is-active` separately?

The following sequence gives me the return value of the first command, not the 2nd as I would have expected (no matter if I run the 1st command in a subshell): sudo systemctl start x; sudo systemctl ...
4
votes
1answer
436 views

Failed to activate systemd-timesyncd.service

I've scanned all forums and questions and found no working answer to my problem. The Network Time Synchronization service doesn't work. The timedatectl service seems to work just fine without it ...
0
votes
2answers
2k views

breaking out of command loop but exit code not the reason?

I run the following: echo "while emacs;do echo $?;done;echo Exit code: $?;" | bash If I exit emacs through the menu or the close button, it prints exit code 0 and restarts. If I exit emacs through ...
0
votes
2answers
25 views

Repeat command execution attempts until status is not specific, preserve data

I have a case where a first few command execution attempts after daemon restart are returning 2 (followed by stderr messages), than everything works correctly. In order to bypass this bug I've come ...
48
votes
4answers
60k 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 ...
6
votes
1answer
24k 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 ...
5
votes
3answers
460 views

bash script executed over ssh returns incorrect exit code 0

I am trying to automate a process which involves running scripts on various machines via ssh. It is vital to capture both output and the return code (for the detection of errors). Setting the exit ...
1
vote
1answer
24 views

Tool to run a command until exit status is 0

Is there a tool that can accept a command and run it over and over until exit status is 0? I could probably check for value of $? in a loop but I wonder if there's a standard program for this
4
votes
2answers
262 views

How to run multiple processes and exit if any of them exits or fails

I am running multiple processes and want to exit with the appropriate exit code (this means error on failure, success otherwise) if any of them fails or exists. Additionally if any child process ...
10
votes
5answers
2k views

Capture exit code of exit command

I have this in a bash script: exit 3; exit_code="$?" if [[ "$exit_code" != "0" ]]; then echo -e "${r2g_magenta}Your r2g process is exiting with code $exit_code.${r2g_no_color}"; exit "$...
9
votes
5answers
34k 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 ...
0
votes
2answers
79 views

how to know who is fail when doing ssh with test

Let's say I want to do some test VIA ssh example ssh 18.23.24.2 2>/dev/null "smartctl -a /dev/sdb -q silent" echo $? 1 in that case we get exit code 1 How to know if the problem is about ssh ...
1
vote
1answer
904 views

The meaning of [ $? == 1 ] && return 0

I need to understand this command: [ $? == 1 ] && return 0
2
votes
1answer
252 views

ldd equivalent which fail when library not found

Assume I perform ldd /bin/ls with the pthread library removed. I obtain linux-vdso.so.1 (0x00007ffcc3563000) libselinux.so.1 => /lib64/libselinux.so.1 (0x00007f87e5459000) libcap.so.2 => /...
0
votes
2answers
159 views

BASH: how can I save the exit code in PS1 in order to use it later in PS1?

I am attempting to customize my PS1, in the following way (I have removed the colours): PS1='\u@\h:\w$(git_branch)$(useExitCode)\$ ' where git_branch() { git branch 2> /dev/null | sed -e '/^[...
0
votes
2answers
2k views

ls error code 2

I was reading the man of ls and in the end it talks about the Exit status of ls. It says: Exit status: 0 if OK, 1 if minor problems (e.g., cannot access subdirectory), 2 if ...
1
vote
1answer
177 views

Redirect YAD results into file AND still give exit codes from buttons to STDOUT

I have 2 custom buttons in my yad --form. The user input aka results get redirected into a .txt file for later use. Thats working fine. But it seems like the exit code is not given to STDOUT anymore, ...
2
votes
4answers
440 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 ...
0
votes
1answer
42 views

Allow automated script to incorporate git rebase

I have this in a script: set -e; base="remotes/origin/dev"; git checkout --no-track -b "$new_branch"; git rebase "$base"; on occasion, there are conflicts of course, and what happens is that git ...
4
votes
1answer
16k views

Capture exit code and output of a command

I'd like to do: 1.sh: #!/usr/bin/env bash set -eu r=0 a=$(./2.sh || r=$?) echo "$a" echo "$r" 2.sh: #!/usr/bin/env bash echo output exit 2 But it outputs: $ ./1.sh output 0 # I'd like to have `...
1
vote
0answers
59 views

Waiting for async console (message queue) output after invoking a command [closed]

I have to work with a command (lets call it update) which somehow prints its output asynchronously to the terminal (mq_timedsend). The output is not recognized as the commands output and therefore the ...
18
votes
2answers
58k views

Exit code at the end of a bash script

I am confused about the meaning of the exit code in the end of a bash script: I know that exit code 0 means that it finished successfully, and that there are many more exit codes numbers (127 if I'm ...
3
votes
4answers
3k views

Bash: Elegant way to set status? [closed]

true && echo foo will print foo. false && echo foo will not print foo. bash -c "exit $a" && echo foo will print foo depending on $a. Is there a more elegant way to write the ...
0
votes
2answers
115 views

Using shell 'printf' where the format string is in a variable and doesn't have a fixed number of field placeholders?

I am writing a shell function which makes an external API call via cURL (the external API syntax isn't under my control). I've approached it like this (simplified): #!/bin/sh template_get_entry='...