Newsgroups: comp.unix.shell
From: mer...@stonehenge.com (Randal L. Schwartz)
Date: Thu, 24 Sep 2009 17:32:47 -0700
Local: Thurs, Sep 24 2009 8:32 pm
Subject: Dangerous use of ls (was Re: Why preceed a "rm" command with a backslash?)
Keith> rm [filespec]
Keith> with (this is just off the top of my head; one can probably be more Keith> ls [filespec] |perl -ple unlink That's scarily bad. I have something akin to my once-famous "useless use of Here's the point. When you say: ls *.c The following happens: 1) the shell expands *.c, into say: aaa.c, bbb.c, ccc.c Why the heck would you make both the shell *and* ls go figure out what files And don't get me started about what would have happened if you had a directory Now, let's go on to the dangerous part, more than just the wasted-CPU part. "perl -ple" reads newline delimited names. (By the way, it also needlessly Suppose you have a file with a name of "aaa\nbbb.c". Yup, that's legal. aaa but Perl sees those as two separate names. If you have an "aaa", Oops. So, slow, and needlessly dangerous. Bad all around. Here's what I think you *might* have meant: perl -e 'unlink @ARGV' [filespec] 1) no useless use of ls And they say shell programming is simple. {sigh} -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||