0

There are other similar questions online out there, but I just couldn't figure out what's wrong with my code after trying those online suggestions. Below is my code:

LineNum = `wc -l <     /data/${INPUT:0:4}/${INPUT:4:2}/positions.$INPUT`
if [2 -le "$LineNum"] 
then
    echo ""
else
    awk 'NR!=1 {print $0}'     /data/${INPUT:0:4}/${INPUT:4:2}/positions.$INPUT | column -t
fi

So the $INPUT is in the format of YYYYMMDD, and I want the file to be displayed if the row count is more then a specific number. But I keep getting the error message "Command Not Found" for the if test.

Any suggestions is highly appreciated!

Andrzej Pronobis
  • 33,828
  • 17
  • 76
  • 92
walkens
  • 61
  • 1
  • 4
  • 11
  • 1
    Don't put spaces around assignments! (``LineNum = `wc -l < file` `` is wrong; ``LineNum=$(wc -l – Jonathan Leffler Aug 17 '15 at 22:42
  • 1
    `[` is a **command**; it's not syntax; it has no special handling by the shell parser at all. Just as you don't use `ls*.txt` to mean `ls *.txt`, you can't use `[2` to mean `[ 2`. – Charles Duffy Aug 17 '15 at 22:47
  • 1
    BTW, http://shellcheck.net/ would have found all these bugs for you automatically, instead of needing to involve humans. :) – Charles Duffy Aug 17 '15 at 22:49
  • Jonathan & Charles, thanks so much for the clear answer!! I'm new to this, and these small things really drive me nuts – walkens Aug 18 '15 at 14:47
  • Charles thanks for the website, this would help me a lot! – walkens Aug 18 '15 at 15:07

1 Answers1

0

You are missing spaces around your condition. Try if [ 2 -le "$LineNum" ].

Andrzej Pronobis
  • 33,828
  • 17
  • 76
  • 92