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:
#!/bin/bash
if ! command -v command_name_here &> /dev/null
then
echo "command_name_here command is not supported!"
exit 1
fi
Alternative solutions
We are able to use &&
or ||
conditions to check command results:
#!/bin/bash
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:
#!/bin/bash
if ! command -v command_name_here &> /dev/null; then echo "command_name_here command is not supported!"; exit 1; fi