[Nottingham] Shell programming

Simon Huggins huggie at earth.li
Sat Dec 18 13:09:11 GMT 2004


On Fri, Dec 17, 2004 at 02:53:53PM +0000, Roger Light wrote:
> On a related note - are there any commands you use that are very
> useful but might not be well known? I'm sure there must be things I
> haven't come across that are really handy. I remember when I hadn't
> heard of tee for instance...

Not commands but I've started using !!$ and !!$:t a lot now in bash.

!!$ means the last argument from the last command.
!!$:t means the filename from the last argument from the last command.

See man bash for more details but it's useful when you edit something
and then want to do something with the file you were editing.

You can also do stuff like:
$ vim /foo/bar/baz
$ ls something_else
ls: something_else: No such file or directory
$ !vim:$
ls /foo/bar/baz				(bash actually prints this to
					stdout before running it)
ls: /foo/bar/baz: No such file or directory

And if you're really showing off:
$ ls /foo/bar/baz
ls: /foo/bar/baz: No such file or directory
$ ls !!$:s/foo/wibble/
ls /wibble/bar/baz
ls: /wibble/bar/baz: No such file or directory

I mostly only remember !!$ and !!$:t though as they're the most useful
to me but there's a lot you can do with bash's history and event magic.

Simon.

-- 
oOoOo "I think we're just out of Waldorfs" - Basil, Fawlty Towers  oOoOo
 oOoOo                                                            oOoOo
  oOoOo                                                          oOoOo



More information about the Nottingham mailing list