TL:DR How do I add a grep to a bash function while allowing a variable number of optional inputs?
I find that in repeated grepping of large outputs, I end up clogging the terminal with data. Sometimes, I want to do a grep, and quickly go to the top of it while capturing all the data. To this end, I have become accustomed with using "clear;clear; grep [options] [string] [file] ; top". Being lazy, I want to turn this into a function called "cgrep", which performs the two clears and the grep. What I have tried is:
cgrep () { clear clear grep "$1" "$2" "$3" }
This works, providing that I always use exactly one optional argument. While that isn't a problem most of the time, I became curious about how to feed it 0-N optional arguments without causing issues (such as reading the [string] as [file]).
I've read this post, and tried a similar implementation. However, this didn't quite suit my needs, and it would be better if I could have the optional parameters between cgrep and [string] to make it look more like a traditional grep.
clear
twice in a row?clear
or terminal emulator. What terminal emulator are you using? What's the output ofecho "$TERM"; clear | LC_ALL=C sed -n l
?