I am trying to write a bash script so that I will use to replace my egrep command. I want to be able to take the exact same input that is given to my script and feed it to egrep.
i.e.
#!/bin/bash
PARAMS=$@
`egrep "$PARAMS"`
But I have noticed that if I echo what I am executing, that the quotes have been removed as follows:
./customEgrep -nr “grep my ish” *
returns
egrep -nr grep my ish (file list from the expanded *)
Is there a way that I can take the input literally so I can use it directly with egrep?
You want this:
The quotes you type are not passed to the script; they’re used to determine word boundaries. Using
"$@"preserves those word boundaries, soegrepwill get the same arguments as it would if you ran it directly. But you still won’t see quotation marks if youechothe arguments.