Skip to content

Named parameters break if the function returns immediately after parameter definition #41

Open
@nkakouros

Description

@nkakouros

Consider this example bash file:

function q() {
  [string] var
}

In the above example, there is no command for the DEBUG trap to hook into. This is expected.

Now consider this:

function q(){
  @required [array] var
  for i in "${var[@]}"; do
    echo $i
  done
}

q "$(@get array_var)"
echo 'Done'

In the above, (it seems that) the var array will be set when the for i in "${var[@]}"; do line gets run. But bash will not even run this line as there is no array to expand. So, it will simply skip the loop and return from the function as there is no other command to run. As a result, the context will change and __assign_paramNo and the other variables will be unset. The @required is there just for the example, it is not crucial to repeating the behavior. If there were more lines after the loop in the function, bash would still skip the loop, but the array would eventually be evaluated when the line after the loop was run.

I haven't found a way to solve this.

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