if ! output=$(some_command);
then
printf "Error occurred, error output is =\n%s", "$output"
Could you please suggest if this is a good way to do it? I am testing - If the exit status of the command is 1, then only I want to print the contents of the output. If the exit status of the command is 0, then do nothing. Don't print output.