Exit statuses with and without pipefail

In Bash on a Linux system, the directory /srv/reports does not exist. GNU ls exits with status 2 when it cannot access a path named on its command line, and grep exits with status 1 when it selects no lines. You run the two lines below once in a fresh shell and once after set -o pipefail.


Shell
ls /srv/reports | grep -v tmp | wc -l
echo $?


Give, as whole numbers: the number that wc -l prints; the value echo prints in the fresh shell; the value echo prints with pipefail set; and the first element of the PIPESTATUS array if you read it immediately after the pipeline instead of running echo.

Your answers

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More The Shell Questions: