I don't like the `require_curl` example.
Here's what is done there:
OK=0
FAIL=1
function require_curl() {
which curl 2>&1 > /dev/null
if [ $? -eq 0 ]
then
return $OK
fi
return $FAIL
}
(`2>&1 > /dev/null` drops stdout and writes stderr to stdout—not what was meant. `which` doesn't write to stderr, so I drop that part.)That can be shortened significantly by using the return code directly in the if branch:
function require_curl() {
if which curl > /dev/null
then
return $OK
fi
return $FAIL
}
Or by just using the return code directly: function require_curl() {
which curl > /dev/null
return $?
}
And as it will return the return code of the last statement executed: function require_curl() {
which curl > /dev/null
}