I’ve got this alias:
alias gi='grep -r -i $1 ./*'
when i do
gi someString
It does the grep, but on some other string than that which I provide, usually with a “p/ or other such thing in it.
I’m using something similar for grepping history:
alias gh='history | grep $1'
Which works perfectly.
EDIT: I am on the /bin/bash shell, as per echo $SHELL.
Thanks!
The
aliasmechanism merely substitutes for a word. Any other words on the same line are left in place, so typically one just replaces the command and leaves the arguments. This doesn’t work well for your grep example because you want to rearrange the line.Now,
$1will refer to the shell process (or shell function) parameters, in either case, not to words typed on the same line.You would be better served in this case with a shell function, which should work on any Posix shell including bash.