Skip to main content
deleted 8 characters in body
Source Link

Thank to muchThanks @rouble for sharing sharing theiryour solution.

For those who need to intercept not only the correct exit code, but also the output of the grep command, here's what worked for me:

echo "before"

grep_exit_code=0
grep_output=$(echo "a" | grep "b") || grep_exit_code=$? ; if [[ $grep_exit_code -ne 1 ]]; then (exit $grep_exit_code); fi

echo "grep_exit_code=$grep_exit_code"
echo "grep_output=$grep_output"

echo "after"

Thank to much @rouble for sharing their solution.

For those who need to intercept not only the correct exit code, but also the output of the grep command, here's what worked for me:

echo "before"

grep_exit_code=0
grep_output=$(echo "a" | grep "b") || grep_exit_code=$? ; if [[ $grep_exit_code -ne 1 ]]; then (exit $grep_exit_code); fi

echo "grep_exit_code=$grep_exit_code"
echo "grep_output=$grep_output"

echo "after"

Thanks @rouble for sharing your solution.

For those who need to intercept not only the correct exit code, but also the output of the grep command, here's what worked for me:

echo "before"

grep_exit_code=0
grep_output=$(echo "a" | grep "b") || grep_exit_code=$? ; if [[ $grep_exit_code -ne 1 ]]; then (exit $grep_exit_code); fi

echo "grep_exit_code=$grep_exit_code"
echo "grep_output=$grep_output"

echo "after"
Add link to the other answer referenced here
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

Thank you soto much @rouble for sharing your solution - saved my ass man, I've been fighting with this in a GitHub Workflow for more than a daysharing their solution.

For those who need to intercept not only the correct exit code, but also the output of the grep command, here's what worked for me:

echo "before"

grep_exit_code=0
grep_output=$(echo "a" | grep "b") || grep_exit_code=$? ; if [[ $grep_exit_code -ne 1 ]]; then (exit $grep_exit_code); fi

echo "grep_exit_code=$grep_exit_code"
echo "grep_output=$grep_output"

echo "after"

Thank you so much @rouble for sharing your solution - saved my ass man, I've been fighting with this in a GitHub Workflow for more than a day.

For those who need to intercept not only the correct exit code, but also the output of the grep command, here's what worked for me:

echo "before"

grep_exit_code=0
grep_output=$(echo "a" | grep "b") || grep_exit_code=$? ; if [[ $grep_exit_code -ne 1 ]]; then (exit $grep_exit_code); fi

echo "grep_exit_code=$grep_exit_code"
echo "grep_output=$grep_output"

echo "after"

Thank to much @rouble for sharing their solution.

For those who need to intercept not only the correct exit code, but also the output of the grep command, here's what worked for me:

echo "before"

grep_exit_code=0
grep_output=$(echo "a" | grep "b") || grep_exit_code=$? ; if [[ $grep_exit_code -ne 1 ]]; then (exit $grep_exit_code); fi

echo "grep_exit_code=$grep_exit_code"
echo "grep_output=$grep_output"

echo "after"
Source Link

Thank you so much @rouble for sharing your solution - saved my ass man, I've been fighting with this in a GitHub Workflow for more than a day.

For those who need to intercept not only the correct exit code, but also the output of the grep command, here's what worked for me:

echo "before"

grep_exit_code=0
grep_output=$(echo "a" | grep "b") || grep_exit_code=$? ; if [[ $grep_exit_code -ne 1 ]]; then (exit $grep_exit_code); fi

echo "grep_exit_code=$grep_exit_code"
echo "grep_output=$grep_output"

echo "after"