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
- 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
- Generate the script with
bashly generate
- 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
Bashly Version
Latest Ruby Gem
Description
The generated
parse_requirementsfunction declares the variablekeywithout thelocalkeyword, causing it to pollute the global scope. This leads to unexpected behavior when user scripts use a variable namedkeyand then call another command viarun().Contents of bashly.yml
Reproduction Steps
key:bashly generatekeyvariable is overwritten after callingrun()Actual Behavior
In
lib/bashly/views/command/parse_requirements_while.gtx:4, the variablekeyis declared withoutlocal:This should be:
Expected Behavior
The
keyvariable should be local to theparse_requirementsfunction and not interfere with user-defined variables in command scripts.Environment
Bashly version: 1.3.3
Bash version: 5.1.16