Find the answer to your Linux question:
Results 1 to 3 of 3
authdisplay=${display:-:0} what is the ":-:0" mean in the above line?...
  1. #1
    Just 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?

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    So this is actually pretty freaky, because this looks like one construct, when it's actually another. So first, what does it look like?
    Code:
    alex@danu ~ $ a=hooha; echo ${a:0:2}
    ho
    alex@danu ~ $ a=hooha; echo ${a:2:3}
    oha
    Which is to say, ${string:x:y} produces a substring of $string, beginning at index x (indexes are 0-based) of length y.

    But this is particularly freaky. Because here, our starting index is '-', obviously not a number. This is because there is another construct:
    Code:
    alex@danu ~ $ a=hooha; echo ${a:-goodbye}
    hooha
    alex@danu ~ $ a=; echo ${a:-goodbye}
    goodbye
    A more formal definition: ${string:-word} produces $string if $string is set and non-empty, and word otherwise.

    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:
    Code:
    alex@danu ~ $ echo $DISPLAY
    :0.0
    So this is an attempt to ensure that $authdisplay always has a value.

    Does this make sense?
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Aug 2007
    Posts
    33
    Yes. Thank you. Excellent explanation.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...