Colon operator in “: ${blank=value}” need explanation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Wayne Luke
    New Bees
    • Jan 2026
    • 3

    #1

    Colon operator in “: ${blank=value}” need explanation

    Colon operator acts like a null, and I knew it's used for parameter expansion, can someone explain this:
    Code:
    [FONT=Calibri][I][FONT=Tahoma][COLOR=#333333]:[/COLOR][/FONT][/I][I][FONT=Tahoma][COLOR=#333333]${SOMETHING='value'}[/COLOR][/FONT][/I][/FONT]
    I know that this sets the environment variable $SOMETHING to 'value'?

    I'm hoping there's a more explanation for this, if you feel that this is enough and right then I need to know from which book it is proved. Given the link

  • Allen H. Lin
    New Bees
    • Jan 2026
    • 2

    #2
    Expression sets SOMETHING to value if it isn't already set and it useful operator to have in many coding situations.

    It also returns the assigned value, so if you simply write ${SOMETHING='value'} at this time your shell would try to invoke the value of command. This may work or may not do something; at the end it will give you a message "value: command not found".

    So to avoid this you use the no-op :, which solve the argument, rather than executing it.


    Comment

    Working...