Originally Posted by christianunix
result=$(cat file|wc -l)
is better than
result=$(wc -l file)
cat file|wc -l will save 7 into the variable, and wc -l file will save "7 file" into the variable
In which case, to avoid using a cat command (which can take a very long time on its own), it's better to use the < redirect, which has the parallel advantages of avoiding the filename becoming part of the output and the unnecessary use of cat:
RESULT=$(wc -l < file)
Also, make sure you use backticks (on my keyboard it's the key above the tab key) _not_ apostrophes or quotes. Backticks have exactly the same effect as $().