...making Linux just a little more fun!
[ In reference to "2-Cent Tips" in LG#152 ]
Ben Okopnik [ben at linuxgazette.net]
Hi, Greg -
On Sat, Jul 26, 2008 at 11:02:39AM -0700, Greg Metcalfe wrote:
> On Friday 25 July 2008 21:02:51 Ben Okopnik wrote: > > On Fri, Jul 25, 2008 at 11:35:02AM -0700, Greg Metcalfe wrote: > > > Regarding "2-cent tip: Removing the comments out of a configuration > > > file": > > > > > > I don't like to invoke Yet Another Interpreter (Perl, Python, etc.) for > > > simple problems, when I've already got a perfectly good one (the bash > > > shell) running, and all those wonderful GNU programs. > > > > You know, I'm often puzzled when people say that. Whether you have Bash > > running or not, your script launches another instance of it - *as an > > interpreter.* The memory footprint of bash plus grep is not going to be > > much smaller than that of Perl, either. You also lose the capability of > > (easily) writing the result back to the original file. In what way is > > this better? > > > The bit about launching another interpreter is forehead-slappingly correct, of > course. I have systems where bash is the only interpreter present. Sendmail's > restricted shell is disabled, etc. I wonder if I'm not subconciously making > peace with that situation, rather than growling about it.
That would be understandable, certainly. I'm a big fan of the functional overlap that is afforded by the various programming tools plus the standard Unix toolkit - it means that you can usually get the job done even when you're missing your favorite gadget. Believe me, I have nothing at all against 'grep' - especially when it's wearing that Superman cape with a '-E' option stenciled on the back.
> My 'dense' actually does other things via switches, such as reporting on local > modifications to config files via a mandated '# LOCALMOD date name reason' > standard, etc. > > But it just growed, and most of it is far too nasty (non-standard switches, > etc.) to ever be seen by the public. I just grabbed the two most relevant > lines, and pasted. You'll have seen my shebang typo, for instance. > The 'dense' that's really in use does have the advantage of actually being > runable...
Heh. I've done a number of those in my time... although after a certain point, I got into a habit of going back and rewriting them if I found that they kept on being useful. I actually have two projects of that sort on the slow burner right now: my lightweight MTA ('bssmtp'), and the LG mailbag processor. The latter actually has a comment in it that says
# This code is a really ugly hack, and I must have # # been smoking really cheap crack when I wrote it. # # It is, however, useful. #
- although that's not quite as true as it used to be. The original had "just growed", since it was driven by what the job demanded - which in turn was driven by the perceived lack of function while using the script. Once it reached the 95% mark or so (i.e., I wasn't hearing any more complaints from our Mailbag Editor, a.k.a. my wife), I started making it look like code written by a professional programmer rather than something akin to the contents of a hobo's knapsack.
> Regarding the bit about writing back to the original file. I suppose that > could be useful, but it's not something I'd want (or be allowed) to do, in > the case of classic config files. In which case, redirection is all that's > needed.
Well, not exactly. 'dense foobar.conf > foobar.conf' would be just as disastrous as any other attempt at "simple" redirection.
> > Is there any reason to have those parentheses in the first part of the > > regex? It works just fine without them. I would also extend the > > definition of 'blank lines' to include lines consisting solely of > > whitespace, and get rid of all those useless backslashes: > > > The parenthesis and backslashes may be an artifact of dragging this over from > some (possibly ancient) version of HP-UX. Provenance might be hard to trace, > particularly as it likely predates the last two version control systems.
Ah. I usually see that kind of thing from cargo-cult coding: "Joe said to use parens; I don't know why, but his code works, and I'm reluctant to screw with it." Not necessarily the cause in your case, but it's often the reason for arbitrary gribble and goo in programs.
> > `` > > egrep -v '^[[:space:]]*(#|$)' /etc/hosts > > '' > > > Simpler, more portable, more powerful. What's not to like? Well, other than > needing to work late a couple of nights next week, grovelling through 'dense' > and a couple of other scripts that are likely just as old. There won't be > time during what I laughingly refer to as normal hours, so the lesson here is > plain. Do not get involved in discussions like this when the weather is nice, > for you may find yourself working late.
I think I know that tune. Been there, done that, hope you got out to enjoy some of the good weather anyway. Thanks for writing!
-- * Ben Okopnik * Editor-in-Chief, Linux Gazette * https://LinuxGazette.NET *