From e384998bc7ed2b5cf14d3389129c9c7f7274eeb4 Mon Sep 17 00:00:00 2001 From: Babak Farrokhi Date: Thu, 27 Aug 2015 15:10:42 +0430 Subject: [PATCH] - make awk code more readable - improve error handling --- netirq_ | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/netirq_ b/netirq_ index 03f24e5..2ea9f63 100755 --- a/netirq_ +++ b/netirq_ @@ -47,11 +47,17 @@ ${VMSTAT} -i | sort -V > ${STATFILE} 2>/dev/null if [ $# -lt 1 ]; then - if [ x${STAT_TYPE} == x ]; then + if [ -z ${STAT_TYPE} ]; then + echo "Should run from symlink" exit 1 fi - cat ${STATFILE} | ${AWK} '{ FS = "[ ]{2,}" } /'${STAT_TYPE}'/{split($1,name,":"); print name[1]".value "$2}' + ${AWK} ' +{ FS = "[ ]{2,}" } +/'${STAT_TYPE}'/ { + split($1,name,":"); + print name[1]".value "$2 +}' ${STATFILE} elif [ "$1" == "suggest" ]; then @@ -65,7 +71,8 @@ elif [ "$1" == "autoconf" ]; then elif [ "$1" == "config" ]; then - if [ x${STAT_TYPE} == x ]; then + if [ -z ${STAT_TYPE} ]; then + echo "Should run from symlink"; exit 1 fi