Search code examples
shellcygwinecho

Printing multiline C++ style comments in shell script


How can you print C++ style multiline comments in the shell script? I want to be able to add a multiline comment automatically to files using a shell script. I've been tinkering around but I can't find a way to add /** in a string. I am using Cygwin on Windows 7.

Here are my attempts so far:

comment="/**"
echo $comment

comment='/**'
echo $comment    

comment="\/**"
echo $comment

But so far, the only result I've been getting with this method is:

/bin /cygdrive /Cygwin.bat /Cygwin.ico /Cygwin-Terminal.ico /dev /etc /home /lib /opt /proc /sbin /srv /tmp /usr /var

comment="\/\*\*"
echo $comment

Prints out \/\*\*...

So how can I echo /** (or **/ for that matter)?


Solution

  • comment='/**'
    echo "$comment"
    

    Always quote variables that could contain glob patterns (otherwise they'll be expanded, as you noticed).

    Since in general you don't know whether that's going to be the case, always quote them unless you have a specific reason not to.