X-Git-Url: https://ruderich.org/simon/gitweb/?a=blobdiff_plain;f=lib.sh;h=1862444f7f560fd9b6eb1922da19423b01459fc0;hb=67e3a3758949c35f395284cb1cea41c4e17c3e95;hp=d9b14c50c8c1851ef1542ed9e2cd7ece5e003d3b;hpb=28014a7a3978f84082fb7e979357e3ff56435887;p=config%2Fdotfiles.git diff --git a/lib.sh b/lib.sh index d9b14c5..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 -ne '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: