Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alias with input. Unix

Consider the following command.

grep -rn "someString" . --color

And I want to alias it in my .cshrc and perform the command like this:

myGrep someString 

Is there a way to do this?

like image 898
Eduard Rostomyan Avatar asked Apr 20 '26 03:04

Eduard Rostomyan


1 Answers

csh records your command in its history list prior to expanding aliases, so you can use history expansion to access arguments to the alias when it is used.

% alias myGrep grep -rn \!:1 . --color

When you use myGrep foo, that two-word command is recorded in history, then it is expanded to grep -rn !:1 . --color. In that command, !:1 refers to the first argument of the previous command (myGrep foo), resulting in grep -rn foo . --color, which is actually executed.

like image 146
chepner Avatar answered Apr 22 '26 18:04

chepner



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!