Search code examples
bashshellunixbin

Make wc -l work with path variable


I need to take action depending on the number of lines in a file. To make it dynamic i use variables with paths and files to use and pass everything to this if statement:

if [[ $(wc -l < $PATH) -gt 1 ]]
then
echo "File has more lines"
fi

When I execute the command with the $PATH I get a wc: command not found as output, when instead of $PATH I give it the path+filename it works.

It wouldn't be much of a problem for it to be static since the file should always be located in that spot and it is produced by a program, but now it is something I want to understand why it does not work.

Thanks in advance.


Solution

  • Bash variable names should be path or filename instead of PATH, because PATH has a specific meaning.