Re: Script to strip illegal characters from files and directories?
- From: Dave B <daveb@xxxxxxxxxxxx>
- Date: Sat, 10 May 2008 18:13:09 +0200
On Saturday 10 May 2008 14:15, Janis Papanagnou wrote:
Yes, but what is the problem; that an error message is displayed?
No, that an useless operation is performed.
The performance advantage of testing is that the test operation
is likely builtin into the shell; but it's also an operation.
But it's not useless, since it avoids spawning an useless additional
process.
even if it does its job correctly. To avoid this, stderr should be
redirected, but then you will also lose real and informative error
messages.
<OT> The point with cron's mail is to *not* lose information. </OT>
With your original script, if one has a directory hierarchy of, say 5000
files, and only 20 or 30 of them need to be renamed, you get ~200K of
*utterly useless* information only for the "mv: foo and foo are the same
file" messages. If there is a single line detailing an I/O error (or some
other real error) buried somewhere inside that huge amount of data, you are
most certainly going to miss it, regardless of whether that information is
sent to you by email or on screen. The cron story was just an example.
More generally, I don't see the point in cluttering stdout with useless
information (where "useless" here means "not related to the main job of the
program"), especially if that can easily be avoided (efficiency matters
aside) by adding a few keystrokes of code. But this is just my opinion, of
course. I have no problem in agreeing to disagree.
And (with bash at least) filenames with trailing spaces will be not
handled correctly if you don't use IFS= for the read (I agree that this
is *really* quite unlikely).
Yes, that's the typical (for c.u.s) paranoia. My experience is that
such names are either created by accident (a mistyped command that
generates a lot of empty files with arbitrary names, e.g.) or by a
malicious user that tries to exploit the unaware Unix admin. Anyway,
I don't think this scenario matches here, and, frankly, I am tired
of demonstrating solutions against such exploits in quite standard
situations. One can - and I've often done that - extend a _single
line_ of commands to two pages code, just to make it bulletprove.
While I mostly agree with you on this, it must be said that sometimes the
solution is just to add a few characters or lines more in the script.
The "--" case is one example. I mean, making things reasonably safe (for
some value of "reasonably") not always means expanding it to two pages. If
the necessary additions are cheap and cost just a few keystrokes, my
opinion is that they can and should be done. Again, this is my opinion
only.
To give you another example; in the program you posted upthread you
missed to check whether the cd command succeeds, and there are also
the unnecessary bash'isms, like local and shopt, and...
Well, I said from the start that it runs under bash, so having said that I
deem not only permissible but highly desirable to use as many bash-specific
features as possible if these come handy, since we're already using bash
anyway. The shopt is to fold the case of empty directories into the general
one, something that would require more code with standard methods. But
still (ok, this is the last time I say that), that is only my opinion.
--
D.
.
- Follow-Ups:
- References:
- Script to strip illegal characters from files and directories?
- From: somebody
- Re: Script to strip illegal characters from files and directories?
- From: Janis Papanagnou
- Re: Script to strip illegal characters from files and directories?
- From: Dave B
- Re: Script to strip illegal characters from files and directories?
- From: Janis Papanagnou
- Re: Script to strip illegal characters from files and directories?
- From: Dave B
- Re: Script to strip illegal characters from files and directories?
- From: Janis Papanagnou
- Script to strip illegal characters from files and directories?
- Prev by Date: Re: Script to strip illegal characters from files and directories?
- Next by Date: Re: Rsync always copies files to fat32 file system on USB drive
- Previous by thread: Re: Script to strip illegal characters from files and directories?
- Next by thread: Re: Script to strip illegal characters from files and directories?
- Index(es):
Relevant Pages
|