wc -l giving integer expression expected error

Solution 1:

I just tried this:

wc -l test.txt

With following result:

5 test.txt

So the result contains a number, followed by the name of the file.

You can solve it like this:

wc -l test.txt | awk '{print $1}'

This only gives the number.

So, you might change your code into:

$ if [ "$(wc -l test.txt  | awk '{print $1}')" -gt "$5" ]; then

... and now correct:

$ if [ $(wc -l test.txt  | awk '{print $1}') -gt 5 ]; then