Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Easy command correction in the shell UNIX
I thought I would pass along this helpful command correction technique. When, using, if I type a command, such as:
 more ~/Library/init/tcsh/aliases.mine 
and then realize that instead of viewing the file I wanted to edit it. The quick way is to type
 pico !* 
The "!*" is a history recall command for the tcsh shell that says "use the arguments 1 through end (generally the second through last words; argument 0 is the command itself) of the previously typed command". So
 pico !* 
expands to
 pico ~/Library/init/tcsh/aliases.mine 
and is executed. If you just want to see the substitution but not have it execute, append a ":p" (for "print") to the "!*", e.g.
 pico !*:p 
[Editor's note: While this may be basic for most of the UNIX wizards, it's a good trick to know for the rest of us!]
  • Currently 3.00 / 5
  You rated: 3 / 5 (1 vote cast)

Easy command correction in the shell | 3 comments | Create New Account
Click here to return to the 'Easy command correction in the shell' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Authored by: bhines on Jun 21, '02 01:09:26AM

This tip is basically more on the "command history" tip i submitted last week. (about "sudo !!")

[ Reply to This | # ]
Off on a tangent
Authored by: pmccann on Jun 22, '02 03:43:37AM

In the same sort of situation that the original poster mentioned it might be worth remembering the following lovely little trick implemented by "less". (I always prefer less over more.)

% less /Users/pmccann/whatever

[[Oops, just realised that I need to change something in that file, not just look at it.]]

Type the letter 'v'. Bingo, you've got the file in question in vi. If you're sitting there saying "yuck, I hate vi" then simply set the "EDITOR" environment variable and less will use that application when you enter 'v'. Suppose you're using tcsh as your shell and wish to have pico as your editor of choice. Simply enter

% setenv EDITOR pico

and you're away. If you'd like this to be more permanent you should probably add that line (without the prompt shown above!) to your .login file in your home directory.


[ Reply to This | # ]
Authored by: pedz on Jun 25, '02 02:10:36PM

I'm surprised the system does not come with bash (a GNU shell). For scripts, csh's syntax is very awkward while bash stays with the more traditional sh syntax. bash also has all of ksh's features.

But, what I really wanted to say is that command history is great. If you get deeper into Unix, you will discover tons of keyboard short cuts since Unix is totally command line oriented. The bash man page, to me, has the best summary of command history and all the other shell stuff in a concise form.

[ Reply to This | # ]