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.
> 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, ...'
Maintained by the ILUG website team. The aim of Linux.ie is to
support and help commercial and private users of Linux in Ireland. You can
display ILUG news in your own webpages, read backend
information to find out how. Networking services kindly provided by HEAnet, server kindly donated by
Dell. Linux is a trademark of Linus Torvalds,
used with permission. No penguins were harmed in the production or maintenance
of this highly praised website. Looking for the
Indian Linux Users' Group? Try here. If you've read all this and aren't a lawyer: you should be!