diff --git a/workflow/qhtcp-workflow b/workflow/qhtcp-workflow index f140664e..ef3a1a2d 100755 --- a/workflow/qhtcp-workflow +++ b/workflow/qhtcp-workflow @@ -263,7 +263,7 @@ ask_pn() { fi fi done - [[ -z ${ADD_PROJECTS[*]} ]] + [[ ${#ADD_PROJECTS[@]} -gt 0 ]] } debug() { (( DEBUG )) && echo "Debug: $*"; } # Not super portable but nice to have @@ -525,22 +525,29 @@ interactive_header() { echo "" # Let user choose or add project(s) - if [[ -z ${PROJECTS[*]} ]]; then + if [[ ${#PROJECTS[@]} -eq 0 ]]; then num=$((${#projects[@]})) if [[ $num -eq 0 ]]; then ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}") else - echo "Enter a comma-separated list of project numbers to analyze" - ((YES)) || read -r -p "Enter \"new\" to add a new project or hit Enter for default ($num): " response - if [[ $response == "new" ]]; then - ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}") - else - [[ -z $response ]] && response=$num - IFS=',' read -ra arr <<< "$response" - for i in "${arr[@]}"; do - PROJECTS+=("${projects[$((i-1))]}") - done - fi + for ((c=0; c<=1; c++)); do # safe loop that only runs once + echo "Enter a comma-separated list of project numbers to analyze" + ((YES)) || read -r -p "Enter 0 to add a new project or hit Enter for default project ($num): " response + if [[ $response == 0 ]]; then + ask_pn && PROJECTS+=("${ADD_PROJECTS[@]}") + else + [[ -z $response ]] && response=$num + IFS=',' read -ra arr <<< "$response" + for i in "${arr[@]}"; do + if [[ -n ${projects[$((i-1))]} ]]; then + PROJECTS+=("${projects[$((i-1))]}") + else + err "Project number $i is invalid" + fi + done + fi + [[ ${#PROJECTS[@]} -eq 0 ]] && c=0 # repeat the loop + done fi unset response arr i fi @@ -553,7 +560,7 @@ interactive_header() { fi done - if [[ -z ${MODULES[*]} && -z ${EXCLUDE_MODULES[*]} ]]; then + if [[ ${#MODULES[@]} -eq 0 && ${#EXCLUDE_MODULES[@]} -eq 0 ]]; then echo "Enter a comma-separated list of modules to run" ((YES)) || read -r -p "Hit Enter for all (default) or '0' for none: " response if [[ -z $response ]]; then @@ -569,7 +576,7 @@ interactive_header() { unset response arr i fi - if [[ -z ${MODULES[*]} && -z ${EXCLUDE_MODULES[*]} && -z ${SUBMODULES[*]} ]]; then + if [[ ${#MODULES[@]} -eq 0 && ${#EXCLUDE_MODULES[@]} -eq 0 && ${#SUBMODULES[@]} -eq 0 ]]; then while :; do echo "Enter a submodule followed by its arguments as a comma-separated string" echo "Quote your string if there are any whitespaces"