File this under #shell #functions I should have written years ago:
function grepc {
#Do a grep -c, but skipping files with no results
grep -c "$@" |grep -v ':0$'
}
File this under #shell #functions I should have written years ago:
function grepc {
#Do a grep -c, but skipping files with no results
grep -c "$@" |grep -v ':0$'
}
"$@"Really? Even if I'm supplying options like grepc -i foo *.md?
Or should I use IFS=$'\n'?
Seems you were right! I need to skim that part of the manpage again. đ
@rl_dane yes. And absolutely no, do not touch IFS for this.
"$@" basically means âpass the argv array as-isâ.
What happens if you forget the double quotes?
$* without double quotesInteresting, that feels kinda counter-intuitive, since not quoting things usually keeps them separate, and quoting them lumps them together, like:
~ $ string="hello there"
~ $ for x in $string; do echo $x; done
hello
there
~ $ for x in "$string"; do echo $x; done
hello there
~ $
"$@" is special, just learn it as a term of its own