Skip to content

scl_source fails under "strict mode"/set -eu #32

@shalomb

Description

@shalomb

If you're in the (good) habit of writing bash scripts under the "strict mode" (i.e. set -eu) then using scl_source will fail.

set -eu
set -xv
...
+ source scl_source enable rh-python36

#!/bin/bash

_scl_source_help="Usage: source scl_source <action> [<collection> ...]

Don't use this script outside of SCL scriptlets!

Options:

    -h, --help    display this help and exit"

++ _scl_source_help='Usage: source scl_source <action> [<collection> ...]

Don'\''t use this script outside of SCL scriptlets!

Options:

    -h, --help    display this help and exit'

if [ $# -eq 0 -o $1 = "-h" -o $1 = "--help" ]; then
    echo "$_scl_source_help"
    return 0
fi

++ '[' 2 -eq 0 -o enable = -h -o enable = --help ']'

if [ -z "$_recursion" ]; then
    _recursion="false"
fi

/usr/bin/scl_source: line 16: _recursion: unbound variable

Current workaround is to disable set -eu temporarily.

    set +eu   # Avoid this -> /usr/bin/scl_source: line 16: _recursion: unbound variable
    source scl_source enable rh-python36  # wtf ? guaranteed this is breaking something else
    set -eu    # And back to sanity

The fix for this may just be that all variables in tests should gracefully default to nothing

㆕ ( unset _recursion; set -eu; [[ $_recursion ]]; )
-bash: _recursion: unbound variable

㆕ ( unset _recursion; set -eu; [[ ${_recursion-} ]] || echo "I say iterate ..."; )
I say iterate ...

or better, make sure they are set at the top of the script.

㆕ ( : ${_recursion:=false}; echo $_recursion )
foo

㆕ _recursion=meh; ( : ${_recursion:=false}; echo $_recursion )
meh

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