matejak / argbash

Bash argument parsing code generator
Other
1.4k stars 62 forks source link

leftover parsing - _our_args is not dereferenced #10

Closed cmeesters closed 7 years ago

cmeesters commented 7 years ago

Hi,

# ARG_LEFTOVERS( .... )

produces

_our_args=$((${#_positionals[@]} - ${#_positional_names[@]}))
for (( ii = 0; ii < _our_args; ii++))
do
    _positional_names+=("_arg_leftovers[(($ii + 0))]")
done

but has to be

for (( ii = 0; ii < $_our_args; ii++))

Tested in the online version as of today.

Best regards, Christian

matejak commented 7 years ago

Hello Christian, are you sure that this is a bug? Does it produce an error message, or does it lead to some unexpected results? I believe that omitting $ in arithmetic evaluation sections is a good practice: https://github.com/koalaman/shellcheck/wiki/SC2004 Nevertheless, I have reviewed the section and I have found some room for improvements, so thank you for reporting it even if it turns out that there is no bug to see 👍

cmeesters commented 7 years ago

Not sure, but it seemed not to loop to the value of _our_args (in my case 150). But I cannot reproduce this.

However, I find the $-notation more readable, since my eyes recognize a variable then. I also would argue that case 1 in the github-link (1+1*5=6) is the correct evaluation. But I see the point and consider it a very dangerous subtlety of bash.

matejak commented 7 years ago

As far as I can see, there are no further problems with this functionality, so I am closing this bug, feel free to reopen if it becomes relevant.