bash-yaml icon indicating copy to clipboard operation
bash-yaml copied to clipboard

How to fix: line 9: $2: unbound variable

Open mmattel opened this issue 4 years ago • 3 comments

Description

To avoid a line 9: $2: unbound variable output when sourcing, change:

local prefix=$2 --> local prefix="${2:-""}"

mmattel avatar Mar 10 '21 12:03 mmattel

Hi @mmattel

Can you provide more informations?

  • What your yaml file looks like?
  • What OS are you using?

jasperes avatar Mar 15 '21 11:03 jasperes

Sure, it was not a matter of the yaml file, but how it got sourced. The OS is Ubuntu 18.04 You can find it running productive at: https://github.com/owncloud/docs/tree/master/bin To make if work with the cli script, I needed to add the suggestion made, while using it with yamltest.sh it worked immediately, and the changes did no harm there. I have marked the changes made in yamlparse.sh BTW, it drove me nuts that dashes in keys got replaced by underscores... There should be a "parameter" to define if you want to transform that or not The reason for using yamlparse was that is based on bash and to dynamically create arguments for another script. The output is further processed with sed to transform the data in a target script digestable way.

mmattel avatar Mar 15 '21 12:03 mmattel

This most likely happens because of set -u somewhere in the script that sources yaml.sh.

@mmattel BASH does not support '-' (dash) in variable names. though I guess you know that, given all you write.

hoijui avatar Apr 13 '23 07:04 hoijui