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.

Filter by
Sorted by
Tagged with
0 votes
1 answer
31 views

What does systemd exit code EXIT_FDS mean?

I get this message from systemd status after I have stopped my service: Actice: failed (Result: exit-code) <...> Main PID: 4747 (code=exited, status=202/FDS) Status FDS is defined in the docs ...
user avatar
  • 123
4 votes
3 answers
588 views

Print exit status code after each command in terminal

I would like to print at every lauched command in zsh exit code value. E.g. $ cat file_not_present cat: file_not_present: No such file or directory Exit code 1 I only know that I can print error code ...
user avatar
0 votes
1 answer
374 views

Systemctl service failed Exit-code

My systemctl Code dont work ● <appname>.service Loaded: loaded (/etc/systemd/system/<appname>.service; disabled; vendor prese Active: failed (Result: exit-code) since Mon 2022-04-04 ...
user avatar
0 votes
1 answer
56 views

grep: if input file is also the output, then why clearing the input file? [duplicate]

Scenario: $ cat t0.txt xxx $ grep xxx t0.txt > t0.txt grep: t0.txt: input file is also the output # exit status 2 $ cat t0.txt <nothing> Question: if input file is also the output AND the ...
user avatar
  • 397
2 votes
1 answer
288 views

Bash named pipes, parallel commands and exit status

I'm trying to use a named pipe so I can keep stdout for status output from a long process. I could use stderr for status output, but I'd like to keep that for errors. Here is an example: #!/bin/bash ...
user avatar
  • 328
0 votes
2 answers
177 views

Exit bash script if a command succeeds

I have some simple smoke test scripts that generally look like: set -e run-command run-other-command echo ok This works great when I expect commands to succeed; if any fails, the set -e will exit ...
user avatar
  • 103
0 votes
0 answers
47 views

Why does this conditional statement, based on exit code, work in the reverse of what is expected? [duplicate]

The script is test.sh. #!/bin/sh if cmp -s file.a file.b; then echo diff else echo same fi When checking the exit code from cmp -s I see: When file.a and file.b are different. cmp -s file.a file....
user avatar
0 votes
2 answers
219 views

Why the Unix command exit with non-zero value in Shell and evaluates to True when used in bash if condition?

The command patch -R -p0 -s -f --dry-run < abc.patch fails with exit code 1 and prints a error message from patch command but when used with negation in a if condition it passes (i.e prints Pass), ...
user avatar
0 votes
1 answer
202 views

Reboot and relaunch a script if error

I have a script (not written by me, I cannot modify it) that has to run for days, that sometimes fails (exits with an error). In this case all I have to do is just reboot the server (there is no ...
user avatar
  • 2,153
1 vote
0 answers
97 views

TAR returns 1 on big directories - how to ignore this?

I'm running the following sequence for backup purposes: $> set -o pipefail $> tar -c /vary/large/folder1 /very/large/folder2 | xz ... | gpg ... | aws ... $> echo "${PIPESTATUS[0]} ${...
user avatar
  • 2,301
5 votes
0 answers
172 views

How to tell systemd to start a service after a clean exit of another service

I'm trying to start a systemd. service after another service exits properly (e.g : in a application it could be exit(EXIT_SUCCESS) ). I've seen that there might be an OnSuccess option in the later ...
user avatar
  • 51
3 votes
1 answer
280 views

When does inherit_errexit not work?

#!/usr/bin/env bash set -e shopt -s inherit_errexit a=$(cat no-such-file) echo survived $ /tmp/a.sh cat: no-such-file: No such file or directory #!/usr/bin/env bash set -e shopt -s inherit_errexit ...
user avatar
  • 2,913
2 votes
1 answer
102 views

zsh pipestatus disappears in the following prompt

I am on zsh 5.8 (arm-apple-darwin20.2.0). Unlike the way PIPESTATUS in bash is available to read during the next shell prompt, pipestatus of pipe in zsh seems to disappear in the following prompt. ❯ ...
user avatar
1 vote
0 answers
17 views

Catch the root command exit code from a regular user [duplicate]

I've been researching umount exit codes for some error cases, running the following command repeatedly: $ sudo sh -c "umount /home; echo $?" And got surprisingly strange results. The error ...
user avatar
  • 111
3 votes
1 answer
386 views

pdsh and command exit code

I would like to use pdsh to assert that a command successfully run on multiple nodes, if the command fails on any nodes the exit code (from pdsh) should be non-zero. Consider the following examples: $ ...
user avatar
  • 133
2 votes
1 answer
459 views

Exit sh script if condition is met

Maybe this is a rookie question, but I am fairly new to sh scripting and I have to wait about two hours to make sure my logic is right, so I just wanted to ask here. I have a sh-script which should ...
user avatar
  • 131
7 votes
1 answer
696 views

Why 'let' exits with code 1 when calculation result equals to 0?

I came across this question whose author had dealt with problem caused by: let x=1-1 exits with code 1. According to bash manual: If the last expression evaluates to 0, let returns 1; otherwise 0 is ...
user avatar
2 votes
1 answer
171 views

Difference between if [ ... and test ... statement in bash

Consider the following: echo "hello" > file.txt is_match1 () { local m m=$(cat "file.txt" | grep -F "$1") if [ -z "$m" ]; then return 1 fi } ...
user avatar
  • 367
0 votes
0 answers
34 views

Why is the test command output backwards? [duplicate]

If I run help test , I get this: Evaluate conditional expression. Exits with a status of 0 (true) or 1 (false) depending on the evaluation of EXPR. Why is this so counterintuitive? Why does it ...
user avatar
  • 101
1 vote
2 answers
346 views

BASH: Change exit status in trap

Can I assign a different exit status to a shell script in a trap handler? Through trial-and-error, I found that calling exit in trap the exit status can be changed. Normal commands, whether fail or ...
user avatar
  • 409
1 vote
1 answer
153 views

zsh: How to store the return code of a statement without triggering `set -e`?

Suppose I want to capture the return code of (exit 56) If I use set -e or a zerr handler, I can no longer do: (exit 56) ret=$? If I use (exit 56) || true to avoid set -e, the return code would ...
user avatar
  • 1,295
0 votes
1 answer
103 views

Unable to detect a failed print on a remote system using ssh

Below is my code on linux that prints a PDF on a remote MACOS system. echo "Printing ssh -p 3335 ibrahimince@localhost 'lp -d Brother_HL_L2350DW_series $HOMEDIR/Printed/$NEWFILE'"; echo &...
user avatar
  • 307
0 votes
1 answer
100 views

best way to fetch the exit code from the redirection document script

if [ ! -z "admin_us" ] then newgrp admin_us<< END command=` abc.sh ` END fi echo $? What we have seen here is, the exit code is always 0, even if the abc.sh fails, what is a better ...
user avatar
0 votes
0 answers
9 views

command result is not helping for creating tunnel when broken

The following code always echos "Not Creating new tunnel connection" regardless if the tunnel exists or not. if ssh -p 3129 myuser@tunnel.myserver.com ls then echo Not Creating new ...
user avatar
  • 149
0 votes
0 answers
51 views

How to find descriptions for exit codes in Linux? [duplicate]

I'm looking for textual explanation of Linux exit codes (like 124 for timeout, 130 for SIGINT received, etc). I thought errno from moreutils does this but it seems it is for looking for error numbers? ...
user avatar
1 vote
1 answer
391 views

python script being killed also stops the while loop from which it was called

I am uploading files using a python script, non-interactively and usually in a screen session. For big uploads, it sometimes happens that the script stops because it is killed (by python or the OS, I'...
user avatar
1 vote
1 answer
85 views

Using named pipe to get process substitution exit codes

I have a script with a fairly complex command with several process substitutions and I need to get the exit codes from the commands in the process substitutions. I'm trying to do so via a named pipe ...
user avatar
  • 2,127
10 votes
2 answers
1k views

Shell script returns 0 exit_status despite syntax error

Consider this script: #!/bin/sh foo=1 if [[ ! -z $foo ]]; then echo abc fi It's using the Bash syntax [[ ... ]] which doesn't work (as expected) when I run it with the default shell on Ubuntu (...
user avatar
0 votes
1 answer
142 views

How do i store the exitcode of a remote sshpass command into a variable in my locally running script

How do I write the exitcode of a remote sshpass command into a variable in my local script for further use? I am using sshpass in order to remotely execute a command. I know that certificate based ...
user avatar
4 votes
1 answer
2k views

Ignore a command's return status in a systemd service

I have the following problem, I am working a script that creates a fifo device file, but I want to return true even if the file exists already. The following snippet is trying to create fifos from the ...
user avatar
  • 203
17 votes
3 answers
4k views

Why does "file xxx.src" lead to "cannot open `xxx.src' (No such file or directory)" but has an exit status of 0 (success)?

Why does file xxx.src lead to cannot open `xxx.src' (No such file or directory) but has an exit status of 0 (success)? $ file xxx.src ; echo $? xxx.src: cannot open `xxx.src' (No such file or ...
user avatar
  • 397
5 votes
5 answers
569 views

why are the definition of true and false in stdbool.h the exact opposite from the UNIX programs true and false?

stdbool.h is usually defined as: #define false 0 #define true 1 (Sources: OpenBSD, musl, etc.) whereas the unix program false - which just has a unsuccessful status code, is defined as: int main(...
user avatar
  • 712
2 votes
1 answer
142 views

Unable to detect print command failure on remote host

I have a remote Mac that is connected to the printer. I trigger the print on my Mac remotely using ssh from my local system using "ssh port forwarding/tunneling" discussed here. Below is my ...
user avatar
  • 307
0 votes
0 answers
2k views

exit status 247 for systemd process

I have a service that I manage with systemd ; to be precise, it runs the daemon for django-background-tasks (but I do not think that this is relevant). Today it died, as follows $ systemctl --user ...
user avatar
  • 251
0 votes
1 answer
164 views

Keep trying a print command LP until successful

I wish to keep sending the printer print command until the print succeeds. If it succeeds printing then it should delete the file. Below is my script. until ssh root@45.76.162.227 'lp -d ...
user avatar
  • 307
5 votes
3 answers
3k views

The paradox of logical AND (&&) and OR (||) in a bash script to check the successful execution of command (exit code of 0 is interpreted as true)

So I well understand that exit code of 0 is considered success in running of a program. Then we use this in bash scripts with logical AND and OR to run the next program based on the exit status of the ...
user avatar
  • 171
0 votes
1 answer
229 views

Zenity buttons not working

So i can't figured out why my cancel button is not working on the confirmation delete zenity box... Can you please explain me ? directory=$(zenity --entry \ --text "Enter a path" \ --...
user avatar
1 vote
1 answer
31 views

Return from higher function, how - if possible?

I have a somewhat difficult time figuring out how - if possible - to return from a higher function, let me show you a POSIX code tidbit: sudoedit_err () { printf >&2 'Error in sudoedit_run()...
user avatar
0 votes
1 answer
778 views

Make bash script always return success

I have an OpenVPN server which triggers a bash script when a connection is established. This script uses wget to post information to another server. Today I noticed that when this other server is not ...
user avatar
  • 571
0 votes
0 answers
41 views

awk command stops the command from completing and returning exit code

I'm on SunOS 5.11 11.1 sun4v sparc sun4v I wish to grab capture the result (success or failed) $? of a command. The below works fine. ps auxww | grep httpd; echo $? Output: 1 But when i add the awk ...
user avatar
  • 307
0 votes
1 answer
69 views

Is there a standard command that always exits with a signal?

This question is very similar to Is there a standard command that always exits with a failure? I'm writing some code which I need to test that it handles subprocesses gracefully when the child process ...
user avatar
  • 111
1 vote
0 answers
100 views

When i use nohup command..Are nohup exit codes same as script return codes

I am using below command in one script abc. Sh Nohup script1.sh $tablename & This script1.Sh passes some returncodes based on success/fail Ex:0-success 99fail When I use exitstatus=$? .. Will this ...
user avatar
0 votes
2 answers
2k views

best range for custom exit code in linux? [closed]

Here I am developing an application that can exit for various custom reasons. What is the best range for a custom exit code (like 150-200)? I know this opinion-based but still i wanted to know the ...
user avatar
1 vote
2 answers
77 views

return code of individual script ,though they are running in parallel

I have jar file which is running in parallel with multiple table names as arguments using nohup command in unix nohup java -jar batchorch.jar $tablename & I have used below lines for getting ...
user avatar
-2 votes
2 answers
2k views

Why do I get command not found for 'ls' when using '$?'?

Assignment problem: Execute 'good' and 'ls' in the terminal and check execution status What I did good;$? output: zsh: command not found: good zsh: command not found: 127 ls;$? output: quiz.sh zsh: ...
user avatar
4 votes
2 answers
1k views

Fail script if command fail but run all commands in any case

There are a few commands in a script I need to run, it's a custom linter for source code. Each run generates a report and fails with exit code 1 in case of rules violations. I need to run all commands ...
user avatar
  • 418
1 vote
3 answers
1k views

Can a program output to STDERR and still return a zero exit status?

I'm working on refactoring some Python scripts intended to be run from the command line. The scripts use logging, which makes some messages be written to STDERR (among other things). I wonder if it's ...
user avatar
5 votes
2 answers
471 views

After command execution, how to determine whether an exit code has been set by bash or by the executed command?

My bash knowledge is a bit rusty (and hasn't been very solid before as well), so I seem to be unable to find an answer to the following question: As the heading says, I'd like to know how I can ...
user avatar
  • 2,213
0 votes
2 answers
105 views

Why does sending a process to background set $? to a non-zero value? [duplicate]

I've just noticed that sending a foreground process to background with Ctrl-Z sets the $? variable to a non-zero value. Why is this the case? This behavior is bothering me, because I wanted to have a ...
user avatar
  • 1,012
-1 votes
1 answer
2k views

What means the RET=$? in the previous reply?

In this thread : https://superuser.com/questions/569092/how-to-split-the-http-error-code-from-the-contents-in-curl What means this part: if [[ $RET -ne 0 ]] ; then # if error exit code, print ...
user avatar

1
2 3 4 5