X-Git-Url: https://ruderich.org/simon/gitweb/?p=config%2Fdotfiles.git;a=blobdiff_plain;f=lib.sh;h=1862444f7f560fd9b6eb1922da19423b01459fc0;hp=1fa3c8fc0fedaea09f27b91769f1f93218a793fb;hb=67e3a3758949c35f395284cb1cea41c4e17c3e95;hpb=3c9f2ee5ea8c7fe57864cad38f4f6188c569fa5d 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: