[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
--
Hello World. David Bronder - Systems Admin
Segmentation Fault ITS-EI, Univ. of Iowa
Core dumped, disk trashed, quota filled, soda warm. [email protected]
_______________________________________________
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/