Results 1 to 3 of 3
authdisplay=${display:-:0}
what is the ":-:0" mean in the above line?...
- 11-28-2007 #1Just Joined!
- Join Date
- Aug 2007
- Posts
- 33
what does this shell script mean ${display:-:0}
authdisplay=${display:-:0}
what is the ":-:0" mean in the above line?
- 11-28-2007 #2
So this is actually pretty freaky, because this looks like one construct, when it's actually another. So first, what does it look like?
Which is to say, ${string:x:y} produces a substring of $string, beginning at index x (indexes are 0-based) of length y.Code:alex@danu ~ $ a=hooha; echo ${a:0:2} ho alex@danu ~ $ a=hooha; echo ${a:2:3} oha
But this is particularly freaky. Because here, our starting index is '-', obviously not a number. This is because there is another construct:
A more formal definition: ${string:-word} produces $string if $string is set and non-empty, and word otherwise.Code:alex@danu ~ $ a=hooha; echo ${a:-goodbye} hooha alex@danu ~ $ a=; echo ${a:-goodbye} goodbye
The second construct is being used here. So ${display:-:0} means the value of $display, if it is available, and ":0" otherwise. In this case, ":0" is the first X display, while the current X display is usually stored in $DISPLAY:
So this is an attempt to ensure that $authdisplay always has a value.Code:alex@danu ~ $ echo $DISPLAY :0.0
Does this make sense?DISTRO=Arch
Registered Linux User #388732
- 11-28-2007 #3Just Joined!
- Join Date
- Aug 2007
- Posts
- 33
Yes. Thank you. Excellent explanation.


Reply With Quote