From 90f4bdabb2a983e1d6ebf35d1ca3b5ba91ea1b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20M=C3=BCller?= Date: Wed, 3 Oct 2018 14:20:24 +0200 Subject: [PATCH] common-helpers.inc: yet a another EvalEx(Auto) rework MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * EvalEx: ensure a command is found in first parameter * EvalExAuto: remove linefeeds on end messages Signed-off-by: Andreas Müller --- scripts/include/common-helpers.inc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/scripts/include/common-helpers.inc b/scripts/include/common-helpers.inc index be131d3..8ff7e75 100644 --- a/scripts/include/common-helpers.inc +++ b/scripts/include/common-helpers.inc @@ -44,10 +44,13 @@ ErrorOut() { # EvalEx executes a command, checks if it succeeds and ouputs messages # It expectes the following parameters: # 1. Command -# 2. Message on start -# 3. Message on successful end -# 4. Message on error end +# 2. Message on start (optional) +# 3. Message on successful end (optional) +# 4. Message on error end (optional) EvalEx() { + if [ -z "${1}" ] ; then + ErrorOut "EvalEx: No command found in first parameter" + fi if [ -n "${2}" ] ; then echo -e "${style_magenta}${2}${style_normal}" fi @@ -70,10 +73,10 @@ EvalEx() { # The end messages are created by extracting first word of start message # and appening 'done' respectively 'failed' EvalExAuto() { - # Catch 'Start...' case - StartAligned=`echo $2 | sed 's:\.: :'` - EndMessageOk="`echo $StartAligned | awk '{ print $1 }'` done." - EndMessageFail="`echo $StartAligned | awk '{ print $1 }'` failed!" + # Remove linefeeds / catch 'Start...' case / extract forst + StartAligned=`echo -e $2 | tr '\n' ' ' | sed 's:\.: :' | awk '{ print $1 }' ` + EndMessageOk="`echo $StartAligned` done." + EndMessageFail="`echo $StartAligned` failed!" EvalEx "$1" "$2" "$EndMessageOk" "$EndMessageFail" }