bash: Variable substitution - Use word if variable name is not-null, otherwise use nothing.
-
Take into account the main readme for this section. README first.
Syntax is:
${name:+word}if the variable $name is not-null, then substitute word otherwise use nothing.
Here Brazil is not-null, has a value of SugarCane
$ Brazil=SugarCane $ Amazon=${Brazil:+NoDeforestation} $ echo $Amazon NoDeforestation
Now change Brazil to be null and try again
$ Brazil="" $ Amazon=${Brazil:+NoDeforestation} $ echo $Amazon $
© Lightnetics 2024