$ ${D:=foo}
foo: not found
$ echo $D
foo
The example above sets variable D to "foo" if it is unset or null. It works fine, but causes the annoying error 'foo: not found'. We can suppress that message with the colon.
$ unset D
$ : ${D:=foo}
$ echo $D
foo
Much prettier!
Also see:
Parameter Expansion (and explanation of the colon utility at the bottom of the page)
No comments:
Post a Comment