Use of ":" (was: Re: mtab very long)

From: Paul Smith (psmith_at_nortel.com)
Date: 05/25/05

  • Next message: Eric van der Paardt: "RE: Small issues, but still annoying"
    To: debian-user@lists.debian.org
    Date: 25 May 2005 08:28:40 -0400
    
    

    %% Maurits van Rees <maurits@vanrees.org> writes:

      mvr> maurits@mauritsvanrees:~$ : > temp

      mvr> Does anyone know any other uses for this ':' command?

    The most common usage these days is in conjunction with :=, like this:

        : ${TMPDIR:=/tmp}

    The := form assigns the value if the variable is empty, but it _also_
    substitutes the value. Adding ":" to the front makes that value a
    no-op.

    If you need to write scripts compatible with older versions of the
    shell, then there are places where you need empty statements. For
    example, in traditional Bourne shells you can't have an empty case
    entry, so if you need it to do nothing, like:

        case $foo in
            bar) : do nothing ;;
            *) echo "bad value: $foo"; exit 1 ;;
        esac

    Also, older shells didn't have the "not" operator for program exit
    codes, and you can't have an empty clause in an if-statement, so if you
    wanted to do something when a program failed you needed to write it:

        if someprogram; then
            : success
        else
            echo "someprogram failed!"
            exit 1
        fi

    HTH!

    -- 
    -------------------------------------------------------------------------------
     Paul D. Smith <psmith@nortel.com>           HASMAT--HA Software Mthds & Tools
     "Please remain calm...I may be mad, but I am a professional." --Mad Scientist
    -------------------------------------------------------------------------------
       These are my opinions---Nortel Networks takes no responsibility for them.
    -- 
    To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org 
    with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
    

  • Next message: Eric van der Paardt: "RE: Small issues, but still annoying"

    Relevant Pages

    • Re: PH/W? - Boots Survey - ?1k - weekly draw
      ... that time he has never offered me anything so appetizing as a dead rat!...He ... did offer me a pile of empty snail shells once....but they had been sucked ...
      (uk.rec.competitions)
    • Re: Howto read file line-by-line in bash
      ... And you oversaw three more problems: empty lines are discarded, ... Using loops in shells always leads to this kind of corner case ... Shells are not meant to be used like that, avoid loops ...
      (comp.unix.shell)
    • Re: 1650, scientific letter to the Queen
      ... Take four large half-cut ball pieces and empty the inside. ... We only need the outer shells. ... half-balls and place them around a metal stick. ... at it's back forward with forward-rolling propellers. ...
      (sci.astro)
    • 1650, scientific letter to the Queen
      ... I would like to present an invention, ... Take four large half-cut ball pieces and empty the inside. ... We only need the outer shells. ... at it's back forward with forward-rolling propellers. ...
      (sci.astro)