On 05/24/2011 01:22 PM, David Bronder wrote:
> [Finally catching up on this thread... This response isn't really about
> the thread subject, though.]
>
> Paul Graydon wrote:
>> It seems almost hardwired into my brain to do:
>> ps waxu | grep [s]sh | awk {'print $2'} | xargs kill
>>
>> Naturally substituting [s]sh with whatever program you want to kill.
>> The [] bash expansion ensuring that the grep command doesn't sneak into
>> the list of PIDs returned by awk.
> That's really not what you want to do. Quote the argument to grep,
> and let grep do the actual pattern expansion, not bash (or ksh, or sh).
>
> The Bourne shell and its derivatives (including bash) will take a
> pattern expression (e.g. * or ? or []) and attempt to expand it based
> on the actual files that might match. If there are any matches, that's
> what the expression expands to. If there are no matches, it uses the
> literal expression as given. I consider that inconsistent behavior.
>
> In Paul's example, that grep wouldn't behave as expected if there was a
> file in the working directory called "ssh".
>
> I cringe when I see coworkers rely on this literal handling of unescaped
> metacharacters, such as "rpm -qa substr*". Most of the time, it would
> do what you expect, but occasionally it may fail in an unexpected (and
> potentially spectacular, depending on the commands being run) way.
>
> IMHO, one thing that csh got right (if a pattern doesn't match, it will
> error out the command) and the sh-family got wrong.
>
> So related to the original thread, always remember to treat special
> characters as special, and escape them if you intend them to be used as
> literals.
>
> =Dave
>
I first learnt to do it:
ps waxu | grep ssh | grep -iv grep | awk {'print $2'} | xargs kill
Why I was told -i I'm not entirely sure, but at the time I just ran with
it still being fairly new to such quirks. Then someone pointed out [s]sh
and I switched to that.. The fact I'm not touching solaris (or similar)
boxes that might react to killall in a different manner struggles to
make its way through my thick skull :)
Paul
_______________________________________________
Discuss mailing list
[email protected]
https://lists.lopsa.org/cgi-bin/mailman/listinfo/discuss
This list provided by the League of Professional System Administrators
http://lopsa.org/