[ale] Bash shell text ALE-NW

David S. Jackson deepbsd at earthlink.net
Fri Jun 21 11:21:16 EDT 2002


On Fri, Jun 21, 2002 at 04:53:04AM -0400 Dow Hurst <dhurst at kennesaw.edu> wrote:
> Hopefully in the future we can reapproach this topic in an advanced talk 
> as David hardly got to start on the real meat of what he had prepared. 

Whew.  When I asked, "Does anyone know what command.com is?" and I got a
blank look from about 15 people, I felt like saying, "Okay, all you
folks who don't know what command.com is, for crying out loud, I hope
you brought a gameboy, because you're about to feel very lost."

In retrospect, I wish I had done that so we could at least get past page
6 (of 55).  But thanks to you guys who jumped in to help explain
remedial concepts.  I was beginning to get pretty sad when I realized
that a large part of the class was just learning to pronounce
"yooo' niks" and "ko mand' lyne".  Thank you.  It was all I could do to
keep from crying into a towel.  :-)

> The LUG at KSU will be holding meetings starting this Fall semester for 
> students with topics specifically focused for newbies.

Sounds good.


> Here is the answer to the shell history problem:
> 
> >!579:2:s/ux//
> 
> Which if the 579th command was:
> >ps auxw | grep dhurst | awk '{print($2)}'  |  xargs kill -HUP
> 
> then what you would get would be:
> 
> >ps aw | grep dhurst | awk '{print($2)}'  |  xargs kill -HUP

Dow, this is such a good question, and I hadn't seen this prior to last
night!  Highly cool.

> Am I right?  

As I read the man page, you could simply go

  you at host]$ !579:s/ux//

and that would give you

  ps aw | grep dhurst | awk '{print($2)}' | xargs kill -HUP

Which is what you want, I think.  But if you go 

  !579:N:s/string1/string2/

I think you're saying "just execute the Nth positional argument as a
command in history command 579 and substitute string1 for string2".  I
think you're telling bash to ignore the rest of the command line and
treat the Nth positional variable as a command in itself.

Example:

  you at host]$ echo one two three four
  one two three four
  you at host]$ !!:4:s/our/lip/
  flip
  bash: flip: command not found
  you at host]$ 

On the other hand, let's say you had an ambiguity or error you wanted to
correct, like:

  you at host]$ echo one two two three four
  one two two three four
  you at host]$

Obviously, you want to remove one of the two "two's" from the string.
But how?  Rather than try to tell bash which positional variable to
substitute, you could try some other regular expression, like:

  you at host]$ !!:s/two two/two/
  echo one two three four
  one two three four
  you at host]$

or 

  you at host]$ !!:s/two //
  echo one two three four
  one two three four
  you at host]$

I think you could get as sophisticated in your regex as you needed in
order to accomplish the same thing.  

I could easily be wrong here, but I think this is what I'm seeing.


-- 
David S. Jackson                        dsj at dsj.net
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
I don't deserve this award, but I have arthritis and
I don't deserve that either.  -- Jack Benny

---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be 
sent to listmaster at ale dot org.






More information about the Ale mailing list