Skip to content

Variable key in parse_requirements function should be declared as local #681

Closed

Description

@chudnyi

Bashly Version

Latest Ruby Gem

Description

The generated parse_requirements function declares the variable key without the local keyword, causing it to pollute the global scope. This leads to unexpected behavior when user scripts use a variable named key and then call another command via run().

Contents of bashly.yml

Reproduction Steps

  1. Create a command script that uses a variable named key:
# src/my_command.sh
key="my_value"
echo "Before run: key=$key"
run other_command
echo "After run: key=$key"  # key is now overwritten
  1. Generate the script with bashly generate
  2. Run the command and observe that the key variable is overwritten after calling run()

Actual Behavior

In lib/bashly/views/command/parse_requirements_while.gtx:4, the variable key is declared without local:

while [[ $# -gt 0 ]]; do
  key="$1"
  case "$key" in

This should be:

while [[ $# -gt 0 ]]; do
  local key="$1"
  case "$key" in

Expected Behavior

The key variable should be local to the parse_requirements function and not interfere with user-defined variables in command scripts.

Environment

Bashly version: 1.3.3
Bash version: 5.1.16

Activity

  1. DannyBen commented on Nov 7, 2025

    @DannyBen
    Member

    Confirmed. Looking into it.

  2. self-assigned this
    on Nov 7, 2025
  3. added this to the 1.3.4 milestone on Nov 7, 2025
  4. DannyBen commented on Nov 7, 2025

    @DannyBen
    Member

    Fixed in #682 - thanks for reporting.

  5. chudnyi commented on Nov 8, 2025

    @chudnyi
    Author

    Thank you, @DannyBen , for your hard work on this library! It's greatly appreciated.

  6. DannyBen commented on Nov 17, 2025

    @DannyBen
    Member

    Fixed and released in v1.3.4.

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions