cancel
Showing results for 
Search instead for 
Did you mean: 

: comment?

SOLVED
Go to solution
Deepak Extross
Honored Contributor

: comment?

After years of using comments like this:
# this is a comment
today I came across a script with
: this is a comment.

Is there any compelling reason, other than to flummox the reader, for one to use a colon instead of the good old hash?
14 REPLIES
Deepak Extross
Honored Contributor

Re: : comment?

oops..that should have gone under 'languages'.
Animesh Chakraborty
Honored Contributor

Re: : comment?

Hi,
:this is a comment
sh: :this: not found.
:(

Did you take a backup?
Scott Van Kalken
Esteemed Contributor

Re: : comment?

Dunno, but I've got another question:

if grep -qx $fs $EXCLUDE
then
: # To cater for ksh as ! command doesn't work
else
print - $block
fi

ksh wouldn't like the use of the : as it has special meaning.
Deepak Extross
Honored Contributor

Re: : comment?

Animesh,
Try with a space after the ':'
Sanjay_6
Honored Contributor

Re: : comment?

Hi Deepak,

From animesh feedback it seems : does not act as a comment line signifier. It seems we have to live with the good old "#" only. Are you sure ":" is there to signify a comment line.

Hope this helps.

Regds
Animesh Chakraborty
Honored Contributor

Re: : comment?

Hi Deepak,
$: this is a comment
$ It works now with space
:)
Did you take a backup?
Michael Tully
Honored Contributor

Re: : comment?

It seems that Deepak has a problem with spaces today..... Maybe I should have bought you that beer, you certainly now deserve it.

Cheers
-Michael
Anyone for a Mutiny ?
Ravi_8
Honored Contributor

Re: : comment?

Hi, deepak

OLD IS GOLD. better stick to that.
never give up
Robin Wakefield
Honored Contributor
Solution

Re: : comment?

Hi Deepak,

The : or null command, is commonly used in if-else-fi blocks, where you cannot get away with executing nothing, e.g.

=====================================
#!/bin/ksh

if [ -f /etc/passwd ] ; then
#
else
echo passwd file missing
fi
=====================================

will fail - you need to put a : in place of the # for this to work. You could negate the if statement, but you may want to modify the script at a later stage with the existing if syntax.

Rgds, Robin.
Volker Borowski
Honored Contributor

Re: : comment?

Robin has a point !
I use a dummy command from good old assembler times, cause ":" can cause these questions.

NOP=1

No OPeration :-)

Keep Assembler alive :-)
Volker
Wodisch
Honored Contributor

Re: : comment?

Hello,

the command ":" is NOT a null command! Actually everything following it is evaluated, substituteted, and such.
So after
: ${x:=wow}
the variabel "$x" conatains "wow" only if it was previously empty!

HTH,
Wodisch
Darrell Allen
Honored Contributor

Re: : comment?

Here's my 2 cents:

: is not a comment. It is essentially a null command. It does not process command line args yet the shell still interprets them. It is sometimes used like a comment because it doesn't do anything and the comments are ignored arguments. The shell is doing the work.

You can create your own null command by creating an empty file. It will work just like Wodisch's example.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
Deepak Extross
Honored Contributor

Re: : comment?


#: ${x:=wow}

#echo $x
wow

#: echo $x


whee..aint this fun?
Wodisch
Honored Contributor

Re: : comment?

evaluated - not executed! :-)