Your question is pretty unclear, and I'm not sure I'm understanding it properly. If I am misunderstanding wrongly, I apologize.
However, if I understand you right, you want to be able to use grep in a way that puts the search pattern at the end of the command, because it's more convenient to copy and paste to the end of a command than it is to copy and paste to the beginning of the command, especially if you're running the command multiple times with different search patterns?
Unfortunately, grep's syntax requires the search pattern to come before specifying the search location.
As I see it, there are two solutions. The first is to define a function:
You could put this in your .bashrc
, or just define it once for the session:
recgrep() {
grep "$1" -R .
}
You could then call the function like this:
recgrep myString
And it would do a recursive search in the current folder for mystring.
The other would be to use ripgrep, which recursively searches by default, instead of GNU grep. It's also faster than GNU grep in my experience.
rg myString
grep
command inside a shell script and running it from your terminal?grep [OPTION...] PATTERNS [FILE...]
. It is unclear what the variable$1
contains, please elaboratemyString
occupy the "$1" placeholder inline