Skip to content

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

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

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