0

I have a shell script that pulls my repository from git. Normally, it receives the credentials and the pull works just fine.

My question is what happens if the credentials are wrong and I get an authentication failure. How can I catch this error and stop the shell script?

jonsca
  • 4,084

1 Answers1

1

All commands return a single-byte value (from 0 through 255) after they have completed executing. Usually a 0 return value indicates success and non-0 indicates some sort of problem. Various shells have constructs that check the 0-ness of the return value and can act upon it.

#!/bin/bash
if git ...
then
  echo "git succeeded"
fi

if ! git ...
then
  echo "git failed"
fi

git ... || echo "git failed"
git ... && echo "git succeeded"