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.
280 questions
1
vote
1
answer
117
views
If fprinting to stderr fails, which error code should a C program return? [closed]
Assume the following C snippet showing a piece of error handling:
#include <sysexits.h>
#include <stdio.h>
…
int main(int argc, char argv*[]) {
int retval=0;
…
if(3!=argc) { /* wrong ...
0
votes
1
answer
95
views
Understanding `bash` options -Ee
In a larger script I have
trap -p
echo "settings: [$-], command: [$*]"
"$@"
echo "return code $?"
and I get the output
trap -- '_shunit_cleanup EXIT' EXIT
trap --...
1
vote
1
answer
176
views
unzip returns exit code 1 on empty archive
I have an valid, yet empty zip archive:
$ file 22.zip
22.zip: Zip archive data (empty)
$ xxd 22.zip
00000000: 504b 0506 0000 0000 0000 0000 0000 0000 PK..............
00000010: 0000 0000 0000
...
6
votes
3
answers
3k
views
In bash, how to capture stdout and the exit code of a command when the -e flag is active?
To capture stdout and the exit code when the -e flag (exit the shell immediately when a command fails) is not set, I would use
OUTPUT="$(my_command)"
exit_code=$?
To capture the exit code ...
1
vote
2
answers
130
views
Need to identify executable files via boolean shell test construct
I am trying to symlink executable files to a bin directory within a docker script. I need a way to identify executables and return boolean status. I've been trying this:
for i in ../src/u-boot/tools/...
0
votes
1
answer
93
views
Why does a program named sl (stream locomotive) always end with an exit status of "1"?
Why does a program named sl (stream locomotive) always end with an exit status of "1"?
sl
Animation sl now running...
$ echo $?
1
Why not zero exit status?
Can I get an explanation? I am ...
2
votes
2
answers
372
views
How to capture exit code of subshell (while in pipe)
somefile contains this:
aaa
bbb
ccc
This is the subshell which can exit before completing all iterations. In my particular case is while but it could be for or until:
cat "somefile" | while ...
0
votes
1
answer
101
views
Evaluating exit code of pipe or fifo
So i have something along the lines of:
set -eo pipefail
ssh localhost "ls; exit 1" | cat > output
I thought pipefail would prevent cat to write to ouput (because of the exit code from ...
1
vote
2
answers
85
views
Ensuring Distinguishable Exit Codes for Shell Scripts
Say I have two shell scripts, a.sh and b.sh, where a.sh calls b.sh somewhere inside. Then, say that b.sh could exit with exit codes 0, 1, or 2.
What are some techniques that can be employed to ensure ...
2
votes
1
answer
151
views
Detect if the previous line was a command or not
I'd like to enable Windows terminal shell integration in bash. (Don't judge me.) One nice feature is that the terminal can show a mark in the scrollbar for each command, with a color depending on ...
0
votes
1
answer
105
views
Does there exist a tar implementation that exits 0 when an error occurs?
Vim runtime commit 3d37231437fc0f761664a7cabc8f7b927b468767 tries to fix a tar-editing plugin by removing the assumption that a filename doesn't contain the words warning, error, inappropriate or ...
1
vote
1
answer
786
views
zsh: check exit code of pipeline of commands
I have long pipeline of commands in zsh script:
pv /dev/sda > sda.raw | sha256sum > sda.raw.sha256 | cut -c61-64 | read SHASUM
how can I check inside an if statement, that all commands exited ...
0
votes
1
answer
321
views
Calling a script from within csh with output redirection
What I would want:
#!/bin/csh
# call /myscriptpath/myscript.any and redirect 2>&1 and get retval and output
set my_msg = `/myscriptpath/myscript.any`
set my_ret = `echo $?`
How to capture the ...
3
votes
2
answers
153
views
How and why does using redirection or writing files within an if statement affect exit code?
In zsh
echo 'a string' > test.txt
echo $?
0
and
[[ $(echo 'a string') ]]
echo $?
0
whereas
[[ $(echo 'a string' > test.txt) ]]
echo $?
1
another example
curl -so 'curl-8.2.1.tar.gz' https://...
0
votes
3
answers
1k
views
Does `return 0` equal `true` (in sourced script to shell's environment)?
I am working on a highly portable script that users shall source to their shells, forcing me to use POSIX scripting.
There are many useful functions in the script, one of them is special though, as ...