diff --git a/.gitignore b/.gitignore index 92f55b9..9130974 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ log/ .tmp .bashew* log +/temp/ diff --git a/bashew.sh b/bashew.sh index d9fc043..a3a818a 100755 --- a/bashew.sh +++ b/bashew.sh @@ -578,42 +578,24 @@ check_script_settings() { IO:print "## ${col_grn}boolean flags${col_reset}:" filter_option_type flag | while read -r name; do - if ((piped)); then - eval "echo \"$name=\$${name:-}\"" - else - eval "echo -n \"$name=\$${name:-} \"" - fi + declare -p "$name" | cut -d' ' -f3- done - IO:print " " - IO:print " " fi if [[ -n $(filter_option_type option) ]]; then IO:print "## ${col_grn}option defaults${col_reset}:" filter_option_type option | while read -r name; do - if ((piped)); then - eval "echo \"$name=\$${name:-}\"" - else - eval "echo -n \"$name=\$${name:-} \"" - fi + declare -p "$name" | cut -d' ' -f3- done - IO:print " " - IO:print " " fi if [[ -n $(filter_option_type list) ]]; then IO:print "## ${col_grn}list options${col_reset}:" filter_option_type list | while read -r name; do - if ((piped)); then - eval "echo \"$name=(\${${name}[@]})\"" - else - eval "echo -n \"$name=(\${${name}[@]}) \"" - fi + declare -p "$name" | cut -d' ' -f3- done - IO:print " " - IO:print " " fi if [[ -n $(filter_option_type param) ]]; then @@ -623,10 +605,8 @@ check_script_settings() { IO:print "## ${col_grn}parameters${col_reset}:" filter_option_type param | while read -r name; do - # shellcheck disable=SC2015 - ((piped)) && eval "echo \"$name=\\\"\${$name:-}\\\"\"" || eval "echo -n \"$name=\\\"\${$name:-}\\\" \"" + declare -p "$name" | cut -d' ' -f3- done - echo " " fi fi } diff --git a/template/script.sh b/template/script.sh index c833acb..5db1b05 100755 --- a/template/script.sh +++ b/template/script.sh @@ -2,7 +2,7 @@ ### ============================================================================== ### SO HOW DO YOU PROCEED WITH YOUR SCRIPT? ### 1. define the flags/options/parameters and defaults you need in Option:config() -### 2. implement the different actions in Script:main() with helper functions +### 2. implement the different actions in Script:main() directly or with helper functions do_action1 ### 3. implement helper functions you defined in previous step ### ============================================================================== @@ -52,7 +52,7 @@ flag|f|force|do not ask for confirmation (always yes) option|l|log_dir|folder for log files |$HOME/log/$script_prefix option|t|tmp_dir|folder for temp files|/tmp/$script_prefix choice|1|action|action to perform|action1,action2,check,env,update -#param|?|input|input file/text +param|?|input|input file/text " -v -e '^#' -e '^\s*$' } @@ -498,39 +498,24 @@ Script:check() { IO:print "## ${txtInfo}boolean flags${txtReset}:" Option:filter flag | while read -r name; do - if ((piped)); then - eval "echo \"$name=\$${name:-}\"" - else - eval "echo -n \"$name=\$${name:-} \"" - fi + declare -p "$name" | cut -d' ' -f3- done - IO:print " " fi if [[ -n $(Option:filter option) ]]; then IO:print "## ${txtInfo}option defaults${txtReset}:" Option:filter option | while read -r name; do - if ((piped)); then - eval "echo \"$name=\$${name:-}\"" - else - eval "echo -n \"$name=\$${name:-} \"" - fi + declare -p "$name" | cut -d' ' -f3- done - IO:print " " fi if [[ -n $(Option:filter list) ]]; then IO:print "## ${txtInfo}list options${txtReset}:" Option:filter list | while read -r name; do - if ((piped)); then - eval "echo \"$name=(\${${name}[@]})\"" - else - eval "echo -n \"$name=(\${${name}[@]}) \"" - fi + declare -p "$name" | cut -d' ' -f3- done - IO:print " " fi if [[ -n $(Option:filter param) ]]; then @@ -540,12 +525,9 @@ Script:check() { IO:print "## ${txtInfo}parameters${txtReset}:" Option:filter param | while read -r name; do - # shellcheck disable=SC2015 - ((piped)) && eval "echo \"$name=\\\"\${$name:-}\\\"\"" || eval "echo -n \"$name=\\\"\${$name:-}\\\" \"" + declare -p "$name" | cut -d' ' -f3- done - echo " " fi - IO:print " " fi if [[ -n $(Option:filter choice) ]]; then @@ -555,12 +537,9 @@ Script:check() { IO:print "## ${txtInfo}choice${txtReset}:" Option:filter choice | while read -r name; do - # shellcheck disable=SC2015 - ((piped)) && eval "echo \"$name=\\\"\${$name:-}\\\"\"" || eval "echo -n \"$name=\\\"\${$name:-}\\\" \"" + declare -p "$name" | cut -d' ' -f3- done - echo " " fi - IO:print " " fi IO:print "## ${txtInfo}required commands${txtReset}:"