-- EDIT --
There were some incorrect statements in the answer, pointed-out by commentators Gordon Davisson and iBug. They have been corrected in this version of the answer. The final conclusion (remove the "$i"
) remains the same though.
wc -l "$i"
will count the lines in the file $i
. If you never used i
as a variable, then i
will be empty and the command will be wc -l ""
. The output of that will be empty on STDOUT en contain wc: invalid zero-length file name
on STDERR. If the variable i
is used, wc
will most likely complain about a non-existing file. The point is, that wc
will not read STDIN.
I also made some incorrect statements about the quoting. As pointed out, between the (
and )
, it is a different quoting context. This can be shown as follows:
$ a="$(/usr/bin/echo "hop")"
$ echo $a
hop
$ b=hop
$ a="$(/usr/bin/echo "$b")"
$ echo $a
hop
Just removing "$i"
from the wc-l
will solve your issue.
if [ "$(git diff | grep pkg/client/clientset | wc -l)" -gt "0" ]; then
echo "Hello"
fi