From 9b5d012ec4c2cfa32f05e3a668bcd2b2d17507ac Mon Sep 17 00:00:00 2001 From: Andrew Robbins Date: Sun, 9 Jul 2017 03:22:45 -0400 Subject: Fix action text in './libreboot usage ' Apparently the name used in a 'for /name/ ...' loop rebinds any local variables (with the same name) with whatever /name/ is bound to in a way that persists even after the loop returns. The crux of the issue here is that a function's children can rebind the parent(s)' local variables just by using the same name as the variable in a for loop, which is surprising--and apparently undocumented--behavior. Use of a subshell group for encapsulating the for loops (See: project_usage_actions) mitigates the aforementioned issue. Closes issue: #244 --- libs/project | 48 +++++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 25 deletions(-) diff --git a/libs/project b/libs/project index 43c6a82c..2728d4fa 100755 --- a/libs/project +++ b/libs/project @@ -556,56 +556,54 @@ project_arguments_targets() { } project_usage_actions() { - local project=$1 + local project="$1" shift printf '\n%s\n' 'Generic actions:' - for action in $PROJECT_ACTIONS_GENERIC - do - if function_check "$action" - then - printf '%s\n' " $action" - fi - done + ( + for action in ${PROJECT_ACTIONS_GENERIC}; do + if function_check "${action}"; then + printf '%s\n' " ${action}" + fi + done + ) - if [ $# -gt 0 ] - then + if [[ "$#" -gt 0 ]]; then printf '\n%s\n' 'Specific actions:' - for action in "$@" - do - printf '%s\n' " $action" - done + ( + for action in "$@"; do + printf '%s\n' " ${action}" + done + ) fi } project_usage_arguments() { - local project=$1 + local project="$1" shift printf '\n%s\n' 'Arguments:' - project_usage_arguments_recursive "$project" " " "$@" + project_usage_arguments_recursive "${project}" ' ' "$@" } project_usage_arguments_recursive() { - local project=$1 + local project="$1" shift - local spacing=$1 + local spacing="$1" shift local action_helper_arguments local argument - action_helper_arguments=$( project_action_helper "arguments" "$project" "$@" ) + action_helper_arguments="$(project_action_helper 'arguments' "${project}" "$@")" - if ! [ -z "$action_helper_arguments" ] - then - printf '%s\n' "$action_helper_arguments" | while read argument - do - printf '%s\n' "$spacing$argument" - project_usage_arguments_recursive "$project" " $spacing" "$@" "$argument" + if [[ -n "${action_helper_arguments}" ]]; then + for argument in ${action_helper_arguments}; do + printf '%s\n' "${spacing}${argument}" + project_usage_arguments_recursive "${project}" " ${spacing}" "$@" "${argument}" done fi } -- cgit v1.2.3-70-g09d2