Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Comment Stripper script for unix

by Abigail-II (Bishop)
on Jun 14, 2004 at 15:06 UTC ( #366571=note: print w/ replies, xml ) Need Help??


in reply to Comment Stripper script for unix

Input:

#!/bin/bash # This is a comment. echo "# This is not a comment" echo \# and neither is this.
Output:
echo " echo \
Your program will strip she-bang lines unless such a line starts with whitespace. However, whitespace isn't optional. The first 2 bytes of the file need to be #!, the kernel isn't going to skip over whitespace (and whitespace certainly isn't mandatory). Furthermore, the base of your program is an extremely symplistic regex - it just removes anything on a line starting at the first #. Your program could as well have been:
perl -nle 's/#.*//; print if /\S/'

But my biggest question is, why do you think this is useful for system administration? I don't know any system administrator who wants to remove comments from his configuration files or from his shell scripts.

Abigail


Comment on Re: Comment Stripper script for unix
Select or Download Code
Re^2: Comment Stripper script for unix
by coreolyn (Parson) on Jun 14, 2004 at 15:10 UTC

    This is an annoying trend that's driving me nuts where I work to.. Somehow they are justifying it in the name of security. ( Even to the point of stripping comments from all applications.)

      I tend to ask people to elaborate on that, and ask them to explain how this is helping security. I also might point out that $ > /secret/file works even better (sure, it has some side-effects, but isn't security important enough that we can justify some side-effects?)

      Abigail

Re^2: Comment Stripper script for unix
by hsinclai (Deacon) on Jun 14, 2004 at 15:35 UTC
    Hi Abigail,

    Your program will strip she-bang lines unless such a line starts with whitespace.
    Are you sure about that? The shebang line is not stripped, if it is the first line, which gets preserved and re-inserted back into the final output..
    update- you're totally right about that, I screwed it up..

    why do you think this is useful for system administration..

    Because removing commented lines lets you get a quick view only of active lines - in a file that might have only a few active lines among several screens of commented lines, e.g. a stock squid.conf file..

    Thanks for the feedback!
      Because removing commented lines lets you get a quick view only of active lines - in a file that might have only a few active lines among several screens of commented lines, e.g. a stock squid.conf file..
      Well, a simple grep -v ^\# will do that. If an "active" line has a trailing comment, it doesn't matter. It also doesn't explain why you want to remove comments from a shell script.

      Abigail

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://366571]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2015-07-04 18:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls