bash: Variable substitution - If variable is unset, set variable to word.



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

    Syntax is:
    ${name=word}

    if the variable $name is unset, then set variable to word.

    Here Brazil is set, has a value of SugarCane, hence no Brazil stays as SugarCane.

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

    Now change Brazil to Brazil1 and try again.

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

Log in to reply
 

© Lightnetics 2024