Artificial intelligent assistant

Redirect the error to /dev/null I have a shell script with the line COMPRESS_OPTION=`which compress` There is no `compress` utility installed in our server, hence it gives the error which: no compress in (/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/oracle/bin) on the screen. So I tried COMPRESS_OPTION=`which compress 2>/dev/null` Even then I am getting error on screen.

Don't use `which`, use the POSIX standard `command -v`. For example:


COMPRESS_OPTION="$(command -v compress)"
[ $? != 0 ] && echo "compress not found" || echo "compress is $COMPRESS_OPTION"


If you don't want to change all the instances of `which` in your script, add a function like the following near the start:


which() {
local w status
w="$(command -v "$1")"
status=$?
[ -n "$w" ] && echo "$w"
return $status
}

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 3aae8127a04e8326362ea302cee2a2c2