-1

Normal grep

wolf@linux:~$ egrep 4.4.4.4 data.csv 
A,4.4.4.4,4.4.4.5,4.4.4.6,3.3.3.3,3.3.3.4
wolf@linux:~$ 

Since I've a lot of data to grep, I've put it on alias.

wolf@linux:~$ alias z="egrep $1 data.csv"
wolf@linux:~$ 

But it doesn't work

wolf@linux:~$ z 4.4.4.4
grep: 4.4.4.4: No such file or directory
wolf@linux:~$ 

It turns out that $1 was missing from the alias.

wolf@linux:~$ alias z
alias z='egrep  data.csv'
wolf@linux:~$

What was the reason behind this?

Wolf
  • 1,501
  • 2
  • 15
  • 37
  • Does this answer your question? [Single or Double quotes when defining an alias?](https://unix.stackexchange.com/questions/189073/single-or-double-quotes-when-defining-an-alias) – muru Oct 21 '20 at 04:13
  • And https://unix.stackexchange.com/questions/3773/how-to-pass-parameters-to-an-alias - what you want can't be done with an alias. Use a function – muru Oct 21 '20 at 04:13
  • Does this answer your question? [How to pass parameters to an alias?](https://unix.stackexchange.com/questions/3773/how-to-pass-parameters-to-an-alias) – AdminBee Oct 21 '20 at 11:39

1 Answers1

5

Try a function instead of alias

z() { egrep -- "$1" data.csv; }

Output

$ z() { egrep -- "$1" data.csv; }
$ z 3.3.3.3
A,4.4.4.4,4.4.4.5,4.4.4.6,3.3.3.3,3.3.3.4
B,1.1.1.1,1.1.1.1,1.1.1.2,1.1.1.3,3.3.3.3
$