Skip to content
Snippets Groups Projects
Closed dash bug with string expansion and assignment of default values
  • View options
  • dash bug with string expansion and assignment of default values

  • View options
  • Closed Issue created

    Noticed when compiling OpenFOAM-v2006 modules with ubuntu bionic (18.04) that the module prefix is not being correctly set. Seems to be a weird bug in the dash shell expansions.

    Starting from any non-root directory

    echo "$PWD"
    -> /home/user/openfoam/BuildEnv/scratch

    dash 0.5.8-2.10 (bionic) shows this

    unset test1
    echo "${test1:=${PWD%/*}}"
    -> /home/user/openfoam/BuildEnv/scratch  <-- WHAT?? Not what we expected

    The additional quotes cause incorrect expansion. Whereas

    unset test1
    echo ${test1:=${PWD%/*}}
    -> /home/user/openfoam/BuildEnv  <-- Expected
    • bash and dash 0.5.10.2-6 (focal) work as expected, with/without quotes
    • quoted expansion with :- works as expected.

    Possible fixes?

    Possible workarounds

    • use unqoted version, but risk fixing it on the next shellcheck
    • explicit if [ -z VAR ]; then ...; fi construct
    • with dirname as : "${VAR:=$(dirname xxx)}

    Linked items 0

  • Link items together to show that they're related.

    Activity

    • All activity
    • Comments only
    • History only
    • Newest first
    • Oldest first