0
x=`su - db2inst1 -c "db2 get dbm cfg" |grep KEYSTORE_LOCATION | awk '{print $5}'`
rc="$?"
echo "${rc}"

this echos a 0.

If I forcefully execute a wrong command

x=`su - db2inst1 -c "db get dbm cfg" |grep KEYSTORE_LOCATION | awk '{print $5}'`
rc="$?"
echo "${rc}"

this gives me an error:

-bash: db: command not found

but still gives a 0 return code. I think its for the assignment. But how do I evaluate for the command.

1 Answer 1

2
set -o pipefail

By default the return value of a pipeline is the exit code from the last command—here, awk '{print $5}'. Turn on pipefail to have the pipeline fail if any command fails, not just the last.

Sign up to request clarification or add additional context in comments.

2 Comments

How do we unset this?
set +o pipefail

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.