I'm trying to write an alias for grep:
# config.fish
alias grepcustom="grep -r $argv ~/"
Basically what I want this to do is a recursive grep on my home directory without having to type everything out (i know im lazy).
When I restart the shell and run grepcustom I get:
$ grepcustom "hello"
grep: hello: No such file or directory
There is a file that contains "hello". If I run grep -r in the shell it works properly. However, the problem seems to be with how my alias identifies the commandline argument "hello". What am I doing wrong?
You're going to need to write an actual function:
$ alias grepcustom="grep -r $argv ~/"
$ type grepcustom
grepcustom is a function with definition
function grepcustom
grep -r ~/ $argv;
end
What happened there? Since I have not defined $argv in my shell, it's replaced by an empty string, and then alias added $argv to make the function work. Let's try with single quotes:
$ alias grepcustom='grep -r $argv ~/'
$ type grepcustom
grepcustom is a function with definition
function grepcustom
grep -r $argv ~/ $argv;
end
That's clearly not right. You want
function grepcustom -a pattern
grep -r $pattern ~/
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With