$_

Steven W. Orr steveo at syslang.net
Wed Jan 10 10:56:55 EST 2007


On Tuesday, Jan 9th 2007 at 16:26 -0500, quoth aluminumsulfate at earthlink.net:

=>> Date: Tue, 9 Jan 2007 09:43:27 -0500 (EST)
=>> From: "Steven W. Orr" <steveo at syslang.net>
=>
=>> =>If y'all haven't tried $_ yet, you should definitely give it a spin!
=>> 
=>> In terms of good practices, (assuming you're using bash) I prefer using !$
=>> 
=>> !$ is the last argument of the last command. It's from the csh history 
=>
=>Using !$ has the advantage that bash shows you the expanded version of
=>the command you are executing.  But !$ doesn't interact with tab
=>completion like $_ does.  Try this:
=>
=>$ ls -al /etc/sysctl.conf
=>$ less $_/<TAB>
=>...turns magically into...
=>$ less /etc/sysctl.conf
=>...and you can hit backspace...
=>$ less /etc/
=>...and fill in something eles
=>$ less /etc/asound.conf
=>
=>In my commands, I've historically (ha ha) avoided ! like the plague
=>because - for me - it has more often than not lead to unexpected
=>results.  Of course, taking the time to learn all the ! forms would
=>probably help with this!  The idea of being able to access parameters
=>other than the last *does* appeal to me.  It sure would be nice if !
=>forms could be expanded in-place and edited before the command was
=>issued.

Given a bunch of defined variables and a history of commands,

a=hello
b=44
c=Wahoo
echo "a = $a b = $b c = $c " ../dirname

You can type something like this on your commandline:

echo "last arg was !!:1 and the file that bings with the letter a in !$/

but when you hit tab completion after the slash to see what's in 
../dirname, it won't work. Besides all the rest of bash that you want to 
learn, you want to learn the readline command shell-expand-line which by 
default is bound to M-C-e. (Try it. It really works.) So when you ask bash 
to perform completion on something weird, just expand the line first and 
then your completion will have something to operate on.

Just like writing C code is a combination of writing things in C as well 
as writing things in cpp, working with bash also gives you access to 
readline. For my money, the readline section in bash should be seperated 
since readline is used by lots of other stuff (e.g., gdb, python, etc...) 
but as long as you know where to find the docs, you're in business.

-- 
Time flies like the wind. Fruit flies like a banana. Stranger things have  .0.
happened but none stranger than this. Does your driver's license say Organ ..0
Donor?Black holes are where God divided by zero. Listen to me! We are all- 000
individuals! What if this weren't a hypothetical question?
steveo at syslang.net


More information about the gnhlug-discuss mailing list