From: Aidan Kehoe (kehoea at domain parhasard.net)
Date: Mon 22 Oct 2001 - 10:53:31 IST
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
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.
> and the previous command is re-executed with the substitution in place. If
> anybody knows of any trickery to do this stuff (or similar tricks) it would
> be very handy. If we have any users who prefer Korn to Bash, any ideas on
> the same mechanisms in ksh?
-- `... when the elephant man broke strong men's necks, when he'd had too many Powers, ...'
This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:12:51 GMT