I use the following command to count lines of code (skipping blank lines and comments) in python scripts:
sed '/^\s*#/d;/^\s*$/d' *.py | wc -l
This works just fine, and I am trying to turn this into an alias.
Seems that I am not escaping some characters properly, because this:
alias loc="sed '/^\s*#/d;/^\s*$/d' \$1 | wc -l"
does not work.
$1
. See for example Can I pass arguments to an alias command? – steeldriver Feb 05 '21 at 11:44loc() { sed '/^\s*#/d;/^\s*$/d' $1 | wc -l }
but calling this with: loc *.py does not produce the same output I expected, what am I doing wrong here?
When I call, in the terminal:
– Dominic Feb 05 '21 at 11:53sed '/^\s*#/d;/^\s*$/d' *.py | wc -l
it produces a different result.loc *.py
the shell expands*.py
and passes the result toloc
, where you only use$1
(i.e. the first matching file). Try changing$1
to"$@"
. – steeldriver Feb 05 '21 at 12:01