Skip to content

temp_file: unbound variable warning from RETURN trap under set -u #11

@sweavs111

Description

@sweavs111

I am reporting an error print I am getting when I run container-mod (including what Claude thinks is the issue). The pipeline still runs and generates intended output but (I believe) exits with non-zero exit code, which caused a pipeline I wrote which uses container-mod to fail. Mostly harmless, just thought you should know!

Description:

When running a pull with --update-repo, the following warning is printed (harmlessly, but noisily):

container-mod: line NNN: temp_file: unbound variable

Root cause:

The script sets set -uo pipefail at the top. Inside cmd_pull, a RETURN trap is registered using single quotes:

trap 'rm -f "$temp_file"' RETURN

Single quotes defer expansion — $temp_file is stored as a literal and only evaluated when the trap fires on function return. On some bash versions (common on HPC systems), the
RETURN trap executes after the function's local variable frame is torn down, so temp_file is unbound at that point. With -u active, this triggers the warning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions