EN
Bash - check if command is supported
8 points
In this short article, we would like to show how to check in Bash script if some command is supported under Linux.
Quick solution:
xxxxxxxxxx
1
2
3
if ! command -v command_name_here &> /dev/null
4
then
5
echo "command_name_here command is not supported!"
6
exit 1
7
fi
We are able to use &&
or ||
conditions to check command results:
xxxxxxxxxx
1
2
3
command -v command_name_here &> /dev/null || echo "command_name_here command is not supported!"
We are able to combine all if
in one line:
xxxxxxxxxx
1
2
3
if ! command -v command_name_here &> /dev/null; then echo "command_name_here command is not supported!"; exit 1; fi