To check if a command is available in a bash shell, I usually do:
command -v $COMMAND >/dev/null 2>&1 || {
echo >&2 "Error: this script requires the command '$COMMAND' to be available"
exit 1
}
What is the equivalent in Windows?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can use something very similar
Granted, this will actually execute the command, but most commands will do nothing without proper parameters. If you want to be more sure, you can use
%command% /? >nul 2&1. This will try to bring the help page for the command, without executing itUpdate:
To avoid executing the command entirely, consider
where.exe. It comes bundled with Vista and Windows 7. For other OSes, you can download it. Please refer to this post on how to download itOnce you have it, you can run it with
/Qswitch to avoid extra output. Return code of 0 means command was found. Once thing that I found is that thewherecommand requires you to supply the extension.One the other end, there is a lengthy discussion here about a batch “one-liner” that works without an extension specified (but actually fails when you do specify an extension)