1747997 Members
4511 Online
108756 Solutions
New Discussion юеВ

: 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 14
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.