X-Git-Url: http://git.grml.org/?a=blobdiff_plain;f=grml-tips;fp=grml-tips;h=77425785d084811c425d5ce999f07b0cde3becab;hb=d70eb3bc988c0793d1e880109836fc8d6d53cb8c;hp=8d5e91a909f24bede9419ca08f3ce3adff20ea14;hpb=b38947b587623d6473f063eecaae6b0c0f335900;p=grml-tips.git diff --git a/grml-tips b/grml-tips index 8d5e91a..7742578 100755 --- a/grml-tips +++ b/grml-tips @@ -4,25 +4,38 @@ # Authors: grml-team (grml.org), (c) Michael Prokop # Bug-Reports: see http://grml.org/bugs/ # License: This file is licensed under the GPL v2. -# Latest change: Mit Nov 01 12:02:06 CET 2006 [mika] +# Latest change: Sam Nov 11 20:01:35 CET 2006 [mika] ################################################################################ TIPSFILE='/usr/share/grml-tips/grml_tips' -# another approach: -# awk 'BEGIN { RS = "-- " } /$1/' $TIPSFILE +if ! [ -r "$TIPSFILE" ] ; then + echo "Error: $TIPSFILE not found. Exiting." >&2 + exit 1 +fi -if [ -r "$TIPSFILE" ] ; then +if [ -x /usr/bin/agrep ] ; then + if [ -n "$1" ] ; then + agrep -d "^-- $" -i "$1" $TIPSFILE && echo "" || \ + ( echo "Sorry, could not find a tip for '$1'. :-(" >&2 + echo 'If you want to submit a tip please mail it to tips@grml.org - thank you!' >&2 + exit 1 ) + else + echo "Usage: $0 " >&2 ; exit 1 + fi +else # workaround solution for systems without agrep :-/ if [ -n "$1" ] ; then - agrep -d "^-- $" -i "$1" $TIPSFILE && echo "" || \ - ( echo "Sorry, could not find a tip for '$1'" - echo 'If you want to submit a tip please send it to tips@grml.org - thank you!' ) + TIP=$(awk "BEGIN { RS = \"-- \" } /$1/" "$TIPSFILE") + if [ -n "$TIP" ] ; then + echo "$TIP" + else + echo "Sorry, could not find a tip for '$1'. :-(" >&2 + echo 'If you want to submit a tip please mail it to tips@grml.org - thank you!' >&2 + exit 1 + fi else - echo "Usage: $0 " ; exit 1 + echo "Usage: $0 " >&2 ; exit 1 fi -else - echo "Error: $TIPSFILE not found. Exiting." - exit 1 fi ## END OF FILE #################################################################