exit-status

Detect if the previous line was a command or not

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 whether the command executed was successful or not. However, if …

Total answers: 1

zsh: check exit code of pipeline of commands

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 successfully? I know about ${pipestatus[@]}, but it is an array. So I …

Total answers: 1

Does `return 0` equal `true` (in sourced script to shell's environment)?

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 it returns true or false status to the …

Total answers: 3

Negate exit status of process

Negate exit status of process In a project, I have a test setup where I read the exit status $? of a command. In my test, I want to ensure that the string foobar is not present in the output. When I run the command: ./program | grep foobar It returns 1, indicating a failure. …

Total answers: 1

Get exit status of the first command in a pipe in the second the command

Get exit status of the first command in a pipe in the second the command My question is similar to Get exit status of process that's piped to another, but I want to get the exit status of the second command in the pipe within the pipe. Here’s an example – false | echo $? …

Total answers: 2

Make systemd treat unexpected exit as failure

Make systemd treat unexpected exit as failure I’m wrapping a 3rd party executable in a systemd service unit to manage it. I can’t alter the behavior of this program and I don’t really trust its exit codes. I would like to treat any exit that was not caused by systemd as a failure, that includes …

Total answers: 1

Why does the "dc" command exit(1) when using q(uit)?

Why does the "dc" command exit(1) when using q(uit)? $ echo "$?" 0 $ echo ‘q’ | dc || echo "$?" 1 Why is using q to quit dc considered an error? (The test was run on Ubuntu 20.4.) Asked By: Ray Butterworth || Source This appears to be a bug in dc code, go …

Total answers: 1

How to print the failed command that caused the script's failure?

How to print the failed command that caused the script's failure? I’m using the -e flag. Usage: #!/bin/bash -e Explained: -e Exit immediately if a simple command (see SHELL GRAMMAR above) exits with a non-zero status When a command in the script fails, the script exits and doesn’t continue to execute the rest of the …

Total answers: 2

How to make a script fail when there is an error in here string?

How to make a script fail when there is an error in here string? I have a script similar to this: #!/bin/bash set -euo pipefail IFS=$’nt’ while read -r l; do echo "${l}" done <<< "$(cat input.txt)" echo Success The command cat input.txt is just an example here to simplify my question. I expected that …

Total answers: 2

Bash IF statement is not behaving as expected

Bash IF statement is not behaving as expected I cannot understand the logic of what’s going on with this simple Bash script: #!/bin/bash # Check if file is present which ./vendor/bin/non_existent_file &> /dev/null printf "Exited with $?nn" if [[ "$?" -eq 1 ]]; then echo "Number is One" else echo "Number is not one" fi …

Total answers: 3

Return value inside unbuffer command

Return value inside unbuffer command I have the following bash code to capture the result of a build while printing the output to the screen and provide parsing of the build results. output=$(unbuffer cmake … | tee /dev/tty) parseErrors ${output} parseErrors does what it sounds like. It parses the output for anything that looks like …

Total answers: 1

Is there a pipefail equivalent for dash?

Is there a pipefail equivalent for dash? I have a perl script that runs a system() call to execute shell commands and I would like to run more than one command and pipe data between them. Something like (in perl): system("command1 | command2"); Perl’s system() uses /bin/sh and since these are running on an Ubuntu …

Total answers: 2

What does systemd exit code EXIT_FDS mean?

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 like this: 202 EXIT_FDS Failed to close unwanted file descriptors, or to adjust passed file descriptors. Starting the …

Total answers: 1

Systemctl service failed Exit-code

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 21:55:20 CEST; 4s ago Process: 1686 ExecStart=/usr/bin/npm start (code=exited, status=203/EXEC) Main PID: 1686 (code=exited, status=203/EXEC) Apr 04 21:55:20 raspberrypi systemd[1]: <appname>.service: Service RestartSec=50 Apr 04 21:55:20 raspberrypi systemd[1]: <appname>.service: Scheduled restart …

Total answers: 1

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

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 returned. (p. 56-57) I’m not so familiar …

Total answers: 1

Ignore a command's return status in a systemd service

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 || and /bin/true as well. How can I …

Total answers: 1