A BASH script I wrote has two requirements.
At the moment I check if they are installed this way and I thought it was a good solution until I had some complaints from users:
command -v fping >/dev/null 2>&1 || { echo >&2 "Sorry but fping is not installed. Aborting."; exit 1; }
command -v ifup >/dev/null 2>&1 || { echo >&2 "Sorry but ifupdown is not installed. Aborting."; exit 1; }
I would like to write this in a way that works for the highest possible numbers of platforms and potential user configuration (a path that doesn't contain /bin or /sbin, for example).
Do you have any suggestion to my check?
PATH
temporarily inside your script, and that you won't get errors adding directories that don't exist. – Chris Davies Feb 14 '20 at 20:15command -v
is the best solution. See Why not use “which”? What to use then? – Devon Feb 15 '20 at 08:08