Skip to content

Error due exit code 1 in bash command #26662

Answered by airtower-luna
CGarces asked this question in Actions
Discussion options

You must be logged in to vote

By default the shell in run steps runs with set -e, so it terminates as soon as any command returns an error (AKA a non-zero exit code).

cgarces:

What is the correct way to evaluate the exit code of one shell command inside “run:”?

Put the command directly into the if condition instead of relying on $?, like so:

run: |
  if dpkg --compare-versions "${{matrix.kernel_version}}" "ge" "5.17"; then
      # things to do if the dpkg call returns 0
  else
      # things to do otherwise
  fi

That way a possible non-zero exit code is handled by the if and doesn’t make the shell exit. 🙂

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants