home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 11.3 My Favorite Is !$ Chapter 11
The Lessons of History
Next: 11.5 My Favorite Is ^^

11.4 My Favorite Is !:n*

I use !$ (11.3 ) a lot. But my favorite bash (and csh ) history substitution is !: n * , where n is a number from 0 to 9. It means "take arguments n through the last argument on the previous command line." Since I tend to use more than one argument with UNIX commands, this lets me type the arguments (usually filenames) only once. For example, to use RCS (20.14 ) and make an edit to article files named 1171 , 6830 , and 2340 for this book, I did:

% co -l 1171 6830 2340

RCS/1171,v  ->  1171
RCS/2340,v  ->  2340
revision 1.8 (locked)
% vi !:2*

vi 1171 6830 2340
3 files to edit
% ci -m"Changed TERM xref." !*

ci -m"Changed TERM xref." 1171 6830 2340

In the first command line (co ), I typed the filenames as arguments 2, 3, and 4. In the second command line (vi ), I used !:2* ; that grabbed arguments 2 through the last (in this case, argument 4) from the first command line. The result was a second command line that had those three filenames as its arguments 1, 2, and 3. So, in the third command line (ci ), I used !* to pick arguments 1 through the last from the previous (second) command line. (!* is shorthand for !:1* .)

You can also grab arguments from previous command lines. For example, !em:2* grabs the second through last arguments on the previous emacs command line (command line starting with "em"). There are lots more of these in article 11.7 .

If those look complicated, they won't be for long. Just learn to count to the first argument you want to grab. It took me years to start using these substitutions - but they've saved me so much typing that I'm sorry I didn't get started earlier!

- JP

Previous: 11.3 My Favorite Is !$ UNIX Power Tools Next: 11.5 My Favorite Is ^^
11.3 My Favorite Is !$ Book Index 11.5 My Favorite Is ^^

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System