Re: [ILUG] Shell expansion questions

From: Padraig Brady (padraig at domain antefacto.com)
Date: Mon 22 Oct 2001 - 11:20:21 IST


Aidan Kehoe wrote:

> Ar an 22u la de mi 10, scriobh Rory Winston :
>
> > I was just wondering if the following is possible in the shell.. I find the
> > $_ variable very handy (gives you the last argument of the previous
> > command), so you can type stuff like:
> >
> > $ vim foobar.c
> > $ cat $_
> > $ gcc $_
> >
> > Is there any way to get any other part of the previous command string? I.e.
> > if I type
> >
> > $/usr/bin/foobar foo.c
> >
> > Can I repeat the command, say like:
> >
> > $$__ bar.c
>
>Yup.
>
>In zsh; in recent bash too; originally from the csh;
>
>!* # The previous command; note no $
>!!:0 # The first word of the previous command; /usr/bin/foobar just above.
>!!:1 # Second word; foo.c above.
>... and so on. Look up history substitution in your manual.
>
> >
> > And $__ (or similar) is expanded into the previous command
> > (/usr/bin/foobar)? Or are there any substitution mechanisms whereby I can
> > type something like
> >
> > $ s/foo.c/bar.c
>
>Hmm. Not that I can think of, but "echo !! | sed 's/foo.c/bar.c/g'"
>would do it. Mightn't be sufficiently shellish for you.
>
^foo.c^bar.c
(stops after first match/replace).
Padraig.



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:12:51 GMT