[comp.sys.att] $_

tanya@adds.newyork.NCR.COM (Tanya Katz) (05/08/89)

In article  <704@icus.islp.ny.us> Lenny Tropiano writes:

>Normally I run /bin/ksh... so for those ksh people they know what "$_" does.
>It basically returns the last argument in the previous command line.  It's
>normally used like so...
>
># chown lenny /usr/mail/LENNY
># chgrp mail $_
># chmod 660 $_
>
>In the last two commands, $_ is substituted with /usr/mail/LENNY, it saves
>on those keystokes ...

The scenario painted in this article, namely stripping the execute
permission from /bin/sh  by using $_ while running sh..
is something I am quite capable of doing!  Ouch!

I gather $_ in ksh is supposed to be similar to csh's !$.  However it
is really quite different.  Even the way it is implemented is different.
In csh, the command & substitution are echoed before being executed, 
so you can see the horrible things you are doing,  even if you can't
quite stop them!!  At least if you could see the the argument expanded
wrong, you can possibly undo the damage.  But, alas there is no
expansion, and even when you call up a history the $_ appears as $_, and
you have to trace it back to the offending line.

Last weekend must have been damage the pc weekend, because I too created
havoc by disconnecting the keyboard.  I was just supposed to be for 
a second, the phone rang just as I did this and sent my computer
into never-never land.  Had to reboot! Ugh!

Never, Never, disconnect the keyboard while the coumpter is up! :-(

Tanya

------------------------------------------------------------------------------
    ###   ######  ######   #####       Tanya Katz       (516) 231-5400 x430 
   #   #  #     # #     # #           
  #     # #     # #     #  #####       ...uunet!ncrlnk!adds!tanya      
  ####### #     # #     #       #      tanya.katz@adds.newyork.ncr.com
  #     # ######  ######   #####       

  Applied Digital Data Systems, Inc.   100 Marcus Blvd., Hauppauge, NY 11788 
------------------------------------------------------------------------------

ekrell@hector.UUCP (Eduardo Krell) (05/09/89)

In article <1083@adds.newyork.NCR.COM> tanya@adds.newyork.NCR.COM (Tanya Katz) writes:
>At least if you could see the the argument expanded
>wrong, you can possibly undo the damage.  But, alas there is no
>expansion, and even when you call up a history the $_ appears as $_, and
>you have to trace it back to the offending line.

Why are you using $_ instead of <ESC>_ ?

<ESC>_ will expand the last word in the previous command line and
you'll see it expanded before you hit return. This works in vi editing
mode.
It can be preceeded with a number n to use the n-th word from the BEGINNING
of the last command instead of the last word.

If you have the ksh book, look at the top of page 116.
    
Eduardo Krell                   AT&T Bell Laboratories, Murray Hill, NJ

UUCP: {att,decvax,ucbvax}!ulysses!ekrell  Internet: ekrell@ulysses.att.com

jep@oink.UUCP (James E. Prior) (05/09/89)

In article <1083@adds.newyork.NCR.COM> tanya@adds.newyork.NCR.COM (Tanya Katz) writes:
...
>Last weekend must have been damage the pc weekend, because I too created
>havoc by disconnecting the keyboard.  I was just supposed to be for 
>a second, the phone rang just as I did this and sent my computer
>into never-never land.  Had to reboot! Ugh!

I've had this happen accidentally.  I can usually recover by plugging the
keyboard back in and pushing many buttons until the computer and keyboard
are back in sync.  Even when you can recover, this can make a mess in an
editor.  Don't intentionally unplug your keyboard, but if it does happen,
you might want to try my crazy method.  I make no claims as to the suit-
ability of this method for your use.  i.e. Do this at your own risk.  It
has worked for me, but might not work for you.  In general, devices of this
type shouldn't be connected or disconnected while the power is on.  
-- 
Jim Prior    jep@oink    osu-cis!n8emr!oink!jep    N8KSM

twb@cbnewsh.ATT.COM (thomas.w.beattie) (05/09/89)

In article <1083@adds.newyork.NCR.COM> tanya@adds.newyork.NCR.COM (Tanya Katz) writes:
>In csh, the command & substitution are echoed before being executed, 
>so you can see the horrible things you are doing,  even if you can't
>quite stop them!!  At least if you could see the the argument expanded
>wrong, you can possibly undo the damage.  But, alas there is no
>expansion, and even when you call up a history the $_ appears as $_, and
>you have to trace it back to the offending line.


In ksh you can have filename generation and $-variables expanded.
Since the expansion is done before entering the command you have a chance
to catch a mistake before pressing <RETURN>.

In EMACS mode: <ESC><ESC> expands the current token, as does <ESC>*
	(In versions 11/16/88 and newer <ESC><ESC> only generates unique
	filenames, <ESC>* generates all matching filenames; before 11/16/88
	they were the same.  Treatment of $-variables is the same for both
	in all versions).
	
I routinely use these sequences to avoid typos and other mistakes.
Check out <ESC>= also.
---
Tom Beattie
att!hoqaa!twb
t.w.beattie@att.com