I googled many solutions but did not find one that fully worked. My own rough working is:
[ $(which curl) -eq "" ] || sudo apt install curl
This doesn't quite work, saying "unary operator expected". I've tried = or ==, so I'm not getting how to do a test like this. Is it possible that the empty output from which curl is a $null and I have to test for that?
Alternatively, is there a way to just run sudo apt install curl and then 2>&null at the end to suppress if it's already installed?
sudo apt -y install curl >/dev/null 2>&1but that is going to fail or hang if the user does not have theirsudopassword cached.curlexists, you just test whether it exists and is in your PATH. Also, you don't know whether (whatever is hidden behind the name curl) is that curl in that version you need. One alternative would be to runcurl --versionand parse its output./usr/bin/curlbe more rigorous (I don't need completely bulletproof, and it would be very odd for someone to put a file there that was not a downloaded version ofcurl). My only question then is: do different distros putcurlin different places, or would/usr/bin/curlbe a reliable cross-platform location?