@command -v gpg 2>/dev/null || { echo "Cound not find gpg. Aborting."; exit 1; }

I saw the following command in a Makefile. I understand that it does the following:

  1. verify is called before build in Makfile
  2. @command is used to not echo the command being run and to not echo the output of the command which will be invoked
  3. -v gpg 2>/dev/null will check the version and if gpg is not found it will redirect the error output(sterr) to null(nowhere)
  4. || { echo "Cound not find gpg. Aborting."; exit 1; } will echo a message and exit the current script with error 1 if the previous command creates an error (returns false which is why || is there)

What I don't understand is -v gpg. When checking the version the -v normally comes after the command. Is there a reason for doing this?

1 Answer 1


The -v is an argument for command builtin not for the gpg, it's not looking for "gpg" version, it's looking to see if any command named "gpg" exist.

From help command:

-v    print a description of COMMAND similar to the `type' builtin

it's similar to type builtin:

$ command -v gpg

If it wasn't able to find the command, it'll return a non-zero exit status, so the "OR" section will be run:

|| { ... }

which will prints out:

Cound not find gpg. Aborting.

with an exit status code of "1".

  • 1
    Perfect explanation, ta! Jun 16, 2017 at 8:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .