Skip to content

lnplay argument parsers shift positional parameters while iterating over "$@" #47

Description

@locriani

up.sh, down.sh, get_rune.sh, show_cln_uris.sh, lightning-cli.sh and get_node_uri.sh all shift inside for i in "$@".

The problem

for i in "$@"; do
    case $i in
        --id=*)
            NODE_ID="${i#*=}"
            shift
        ;;
        --port=*)
            PORT="${i#*=}"
            shift
        ;;
        *)
        ;;
    esac
done

for i in "$@" expands the positional parameters once, so shift never advances the iteration -- it only mutates $@ underneath the loop. lightning-cli.sh and get_node_uri.sh additionally pair this with an empty *) branch, so unknown arguments are accepted silently; the other four echo and exit.

Why it matters

The shape cannot parse an option whose value is a separate word, and lightning-cli.sh forwards the post-shift $@ to lightning-cli, so the mutation reaches the wrapped command. Whether any current invocation order actually misfires is unmeasured.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions