Testing for Executables

13 views
Skip to first unread message

Joaquin Menchaca

unread,
Nov 13, 2015, 7:17:01 PM11/13/15
to bash tips
I did this, but is there a cleaner way?

[ -z $(which wget) ] && { echo "ERROR: Wget not found. Install wget"; exit 1 ; }

RJ

unread,
Nov 15, 2015, 1:53:55 AM11/15/15
to bash tips
I would recommend not writing it all in one line (https://google.github.io/styleguide/shell.xml)

What about:
which wget 2>&1 >/dev/null
code=$?
if [[ $code -ne 0 ]]; then
    echo "ERROR: Wget not found. Install wget"
    exit $code
fi

However, if you must do it on one line:
[[ $(which wget) ]] && { echo "ERROR: Wget not found. Install wget"; exit 1; }
Reply all
Reply to author
Forward
0 new messages