what does :=0 mean in shell scripting

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rasmidas
    New Member
    • Jun 2007
    • 56

    what does :=0 mean in shell scripting

    Hi,

    Could anyone please let me know what does it mean by the following statement in solaris shell scripting.

    $PROMPT " Select an option: "
    read ans
    db_option=${ans :=0}

    I wanted to know the interpretation for this last line. what does it mean by :=0

    Please let me know asap.
  • Sageword
    New Member
    • Oct 2008
    • 6

    #2
    One would think it means 'oh-no!!!'

    Truth is, it is a bash shell construct for assigning a default value. In this case, it means 'if they don't give me a value, use zero'.

    Google up bash-shell default-value for info, or see here, about 2/3's of the way down the page, for a default values title.

    http://www.ibm.com/developerworks/library/l-bash-parameters.html ?ca=drs-

    The section offers a slightly technical recap that talks about :+, :-, := and :? Luckily, the more technical part is something most users won't need right away -- it gets into substitution timing (before or after using the default), and it also has a snippet of code you can experiment with until you get the hang of the nuances, *if you really need 'em*.

    G'luck, mate.

    Comment

    Working...