From 3b23840277fef590fbdacb66bcfa3f07f5b6db4d Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Wed, 10 Apr 2019 11:12:28 +0100 Subject: [PATCH] support multiple shell arguments (e.g. -v -q) new verbose output (-v) to echo commands called with exe() before execution --- seqTemplate.sh | 2 +- sequencer/sequencer.sh | 68 +++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/seqTemplate.sh b/seqTemplate.sh index b26394e..2bbe7d9 100644 --- a/seqTemplate.sh +++ b/seqTemplate.sh @@ -13,7 +13,7 @@ step_1_info() { echo "Step $1 header"; } step_1_alias() { ALIAS="begin"; } step_1() { - cat .nofile + exe cat '.no f"le' saveReturn $? } diff --git a/sequencer/sequencer.sh b/sequencer/sequencer.sh index 4dd3a9b..2cbcad7 100755 --- a/sequencer/sequencer.sh +++ b/sequencer/sequencer.sh @@ -13,6 +13,7 @@ VERSION_MINOR=0 ## Start of generic script part QUIET=0 +VERBOSE=0 ERNO=0 MAX_STEP=255 ALIAS= @@ -24,10 +25,12 @@ helpSequencer() { echo "Usage: ${0##*/} [OPTIONS] [STEP NUMBER(s) or ALIAS]" echo echo " [OPTIONS]" - echo " --help, -h : Display help" - echo " --quiet, -q : Don't ask for permission to execute steps" - echo " If called without starting step number, only this help is shown" - echo " --version,-v : Display version of sequencer and revision of sequence" + echo " --help, -h : Display help" + echo " --quiet, -q : Don't ask for permission to execute steps" + echo " If called without starting step number, only this help is shown" + echo " --verbose, -v : Verbose output (use exe() function to call shell commands in seqs)" + echo " ( e.g.: exe apt update )" + echo " --version : Display version of sequencer and revision of sequence" echo echo " [STEP NUMBER(s) 1-${MAX_STEP} or ALIAS]" echo " Single STEP or ALIAS : starting point of process" @@ -331,29 +334,46 @@ showVersion() { fi } +exe() { + arr=("$@") + if [ $VERBOSE -eq 1 ] ; then + (set -x; "${arr[@]}") + else + "${arr[@]}" + fi +} + main() { local START=0 - # option check - case "$1" in - --help|-h) # show only help - displayHelp - exit 0; - ;; - --quiet|-q) # detect if option quiet is available - QUIET=1 - shift - ;; - --version|-v) # version request - showVersion - exit 0; - ;; - "") # Empty -> show help - displayHelp - # Assume starting at one for interactive mode - START=1 - ;; - esac + # options check + for arg in "$@" ; do + case "$arg" in + --help|-h) # show only help + displayHelp + exit 0; + ;; + --quiet|-q) # detect if option quiet is available + QUIET=1 + shift + ;; + --verbose|-v) # set verbose flag + VERBOSE=1 + shift + ;; + --version) # version request + showVersion + exit 0; + ;; + esac + done + + if [ -z $1 ] || [ "$1" == "" ] ; then + # Empty -> show help + displayHelp + # Assume starting at one for interactive mode + START=1 + fi # compatibility check of sequence if [ ! -z $VERSION_SEQREV ] && [ $VERSION_SEQREV -gt $VERSION_REV ] ; then