Interactive csh or tcsh doesn't do comments. The #
character introduces a comment only in a script. (This is unlike the behavior of sh and its derivatives. In bash and zsh, the behavior is configurable.) Quoting the csh
man page (from Solaris 9, one of the remaining systems where csh
is not just a symlink to tcsh
):
When the shell's input is not a terminal, the character #
introduces a comment that continues to the end of the input line.
Its special meaning is suppressed when preceded by a \ or enclosed in
matching quotes.
The point, I think, is that interactive commands don't need comments.
If you're using tcsh, you can do something similar with the built-in :
command, which does nothing:
% : 'This is not a comment, but it acts like one.'
(where %
represents the shell prompt and :
is the command). Quoting the argument is a good idea; otherwise, though the command is not executed, it can have some effect:
% : This will create the file "oops.txt" > oops.txt
Note that since :
is a command, it must be followed by a space.
The :
command was originally introduced in a very early version of the Bourne shell, or perhaps even before that.
However, the /bin/csh
version of the :
command does not permit any arguments, making it useless as a comment replacement:
csh% : 'This will not work.'
:: Too many arguments
csh%
(I didn't realize that when I initially posted this answer. I must have tested it with tcsh rather than a true csh.)
Since :
doesn't work in pure csh, the next best solution is probably to use echo
and redirect the output:
csh% echo 'This is not a comment, but it acts like one.' > /dev/null
Obligatory link: http://www.perl.com/doc/FMTEYEWTK/versus/csh.whynot
rm *#
. Put that in a script and something different happens. – Enneahedron#
comment can be at the beginning of a line. Otherwise, you need whitespace separating it from the preceding token.echo foo#bar
prints "foo#bar";echo foo #bar
prints "foo". – Forethoughtful:
works in csh (as opposed to tcsh). – Forethoughtfulinteractive_comments
,interactive-comments
, orINTERACTIVE_COMMENTS
. – Forethoughtful