bash: Variable substitution - Use variable name if set otherwise use word.



  • Take into account the main readme for this section. README first.

    Syntax is:
    ${name-word}

    if the $name variable is set, then substitute its value, otherwise use word

    Here Brazil is set, has a value of SugarCane

    $ Brazil=SugarCane
    $ Amazon=${Brazil-NoDeforestation}
    $ echo $Amazon
    SugarCane
    

    Lets's change Brazil variable to Brazil1 and try again. Brazil1 is not set.

    $ Amazon=${Brazil1-NoDeforestation}
    $ echo $Amazon
    NoDeforestation
    

Log in to reply
 

© Lightnetics 2024