Thursday, July 31, 2008

Shell, recall last argument

This is also very good shell feature, but many times I failed to use. I will encourage myself by posting this. Here we go.

Suppose I created a temp dir, and move to it.

$ pushd .
$ mkdir /tmp/lalala
$ cd /tmp/lalala

The last command can be easily made by, recall by arrow-up, ctrl-A, remove 'mkdir', and type cd. Not bad, but bash has better option.

$ pushd .
$ mkdir /tmp/lalala
$ cd !$

Confused or frowned for another cryptic symbol memorization? That was my first impression. But, actually not. It is very elegant usage.

! is history recall. As we usually do "$ !510" - recall command number 510 in history.
$ is regex. End of line. Then, we can think usage of '!^'.

$ cat a b c d e
$ cat !^
cat a

So, each run will remember previous argv vector, and we can call by placer(^,$).
Another nice feature. I am interested in middle one, like c in previous example.

$ cat a b c d e
$ cat !:3
cat c

Not bad. Here is another interesting one.

$ cat a b c d e
$ cat !:1-
cat a b c d
$ cat !:1-
cat a b c

Popping every argument..
In my opinion, this is a gift from bash for who think before hand. Someone who lavishes meaningless 'ls', like me, wouldn't get benefit. :)


TechnoSnack's said...


I'm Susan, of the TechnoSnack's team and I wish to inform you that we are opening a new blog aggregator about Computers & Internet news.
We put it on-line some hours ago and the link is:

The main objective of this project is creation of a "virtual dashboard" of posts coming from many specialized blog and information about Computers & Internet world, with news about Linux, Windows, Mac, Open sources, Security, Graphics, Symbian and more on...

The key feature is that news come directly from blogosphere. We wish to show a preview of posts, with a link "Read more..." to signed blogs. If users are interested in news, they are redirected to your blog and can read entire post directly from your blog!

So, the different signed blogs can increase their visibility and reach more visitors, all over the world!

We think that in a little of time it can send more visitors to re gistered blogs, contributing to diffusion of know-how about Computer and Technology world.

I visited your blog and I think it has very interesting and useful posts!

So, are you interested in this idea, with your blog?
If yes, then you can register your blog, using the specific "Registration Form"!


The only thing we ask to you is to insert TechnoSNACK banner in your blog to promote this project. Or, if you prefer, you can insert a link in your blogroll.

If you like (we whould be happy, but it is not mandatory :-), you can write a post regarding TechnoSNACK project in your blog, to promote this idea.

Susan - TechnoSnack's Team

Raymond said...

Thanks, but no thanks.