Funny thing happened to me ... Beware of "$_" and the shell you run

Richard Foulk richard at uhccux.uhcc.hawaii.edu
Tue May 30 22:52:25 AEST 1989


} 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 ...
} 
} Well that's normal and dandy for anyone running /bin/ksh, but what happens
} if your shell is /bin/sh ...  If you echo $_ while running /bin/sh, you'll
} notice it returns /bin/sh.  Now what happened to me...  /bin/sh's group was
} changed  to mail, and the permission was 660.  Ut oh.   Well I didn't quite
} notice this right away... I just logged out normally, thinking everything
} was set.

Looks like another good reason to stick with csh.  !$ is easier to type
and it displays the substitution so you know what's going on.


Richard Foulk		richard at uhccux.uhcc.hawaii.edu



More information about the Unix-pc.general mailing list