Questions tagged [pipestatus]

8 questions
2
votes
1 answer

Maintain exit code from bash command despite output being piped through sed

I just noticed that some of my CI jobs returned OK even though compilation failed. This was essentially because the bash command called to compile the code, while failing and returning 1, had its output piped through sed to add some colours etc to…
JHH
  • 8,567
  • 8
  • 47
  • 91
2
votes
2 answers

PIPESTATUS ignores negation?

I just found the following results in bash (version 4.2.25(1)-release): $ true; echo "${PIPESTATUS[@]}" 0 $ ! true; echo "${PIPESTATUS[@]}" 0 $ false; echo "${PIPESTATUS[@]}" 1 $ ! false; echo "${PIPESTATUS[@]}" 1 $ true && false; echo…
Alfe
  • 56,346
  • 20
  • 107
  • 159
1
vote
1 answer

Getting the exit status of a nested command inside a redirect attached to tee

I have this command: coverage report | tee >(grep TOTAL | awk '{exit (int($4) >= 75)?0:1}') && (exit ${PIPESTATUS[0]}) which reports the code coverage and then prints the output to stdout and redirects that same output to a grep + awk, which…
alexandernst
  • 14,352
  • 22
  • 97
  • 197
0
votes
1 answer

Capturing exit status of child process different on CentOS 6 and Ubuntu 20.04 (in Perl)?

I am adapting a perl backup script from CentOS 6 to Ubuntu 20.04. The subroutine ExecCmd() starts a child process for a system call to rsync. On CentOS 6 it populates a variable $ExecCmdOut with the rsync output and returns the exit status,…
0
votes
3 answers

PIPESTATUS[0] in BASH script

I am implementing a scenario in Unix Bash scripts. I have two scripts ABC.bash and XYZ.bash. There is one condition in ABC.bash when requester does not enter Y or y scripts exit with message and do not work further. ABC.bash working fine when runs…
Vivek Pandey
  • 3
  • 1
  • 4
0
votes
1 answer

How set an exit code when exiting bash?

I want to run a command from a sub-bash and I need the return code from it; actually it's running a pipeline and I need the PIPESTATUS array, or at least one component. This was my best guess and it does not work. I just get a 0. Since bash did not…
TimDev
  • 85
  • 10
0
votes
1 answer

Is PIPESTATUS of processes running in background trackable?

Extending the question as suggested by Cyrus, I wanted to know if I could track the same script with PIPESTATUS or something similar if I sent it to run in background? bash script is as follows: #! /bin/bash { python script.py 2>&1 | tee…
Mihir Luthra
  • 6,059
  • 3
  • 14
  • 39
0
votes
2 answers

repeat pipe command until first command succeeds and second command fails

I am trying to figure out how to get my bash script to work. I have a the following command: curl http://192.168.1.2/api/queue | grep -q test I need it to repeat until the first command in the pipline succeeds (meaning the server responds) and the…
user2328273
  • 868
  • 3
  • 12
  • 22