Given a filepath, I would like to find out how many lines there are and store them into a variable. For example:
/three_little_pigs.csv
straw
wood
bricks
In a file, I would like to have the number (or string 3
) stored. Tried the following commands:
export P="three_little_pigs.csv"
NUM_LINES=(wc -l < "${P}")
but I'm always getting this error:
bash: house: line 12: syntax error near unexpected token `<'
NUM_LINES=(wc -l < "${P}")
but ratherNUM_LINES=$(wc -l < "${P}")
Also no need to capitalize the var name and just simply"$P"
– Valentin Bajrami Jul 24 '17 at 07:20export
for the code you’ve shown. – G-Man Says 'Reinstate Monica' Jun 23 '20 at 22:24