From: Simon Ruderich Date: Mon, 29 Mar 2010 00:43:19 +0000 (+0200) Subject: lib.sh: Don't require perl in installed(), instead use awk. X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=67e3a3758949c35f395284cb1cea41c4e17c3e95;p=config%2Fdotfiles.git lib.sh: Don't require perl in installed(), instead use awk. --- diff --git a/lib.sh b/lib.sh index 1fa3c8f..1862444 100644 --- a/lib.sh +++ b/lib.sh @@ -11,7 +11,11 @@ unset LS_COLORS # Check if the given program is installed. Returns 0 if it exists, 1 # otherwise; so it can be used in if. installed() { - which $1 2>&1 | perl -e '$_ = <>; if (not m{^/}) { exit 1 }' + # Thanks to Rado in #awk on Freenode (2010-03-29 01:34) for the END tip to + # also work with empty stdin, and to prince_jammys in #awk on Freenode + # (2010-03-29 02:20) for a shorter syntax for "$0 !~". + which $1 2>&1 | awk '{ if (!/^\//) exit 1 } + END { if (NR == 0) exit 1 }' } # Print the current OS. The following OS are supported at the moment: