0

I have syntax error in my code to move files if the statement is true.The code goes on forever.Also tried adding quotes but unable to.I know there would be some silly mistake that I am doing.

for file in *.sort; 
do if [`wc -l` $i -eq 57817]; 
then mv "$i" "../$i"; 
fi; done

Any suggestions?

1
  • 5
    www.shellcheck.net Commented May 9, 2019 at 15:31

1 Answer 1

6
  1. You need a space between [ and the conditions
  2. $i is not being set
  3. Your command substitution does not include the entire command (wc -l file is the entire command, you are only wrapping around wc -l)
  4. wc -l file will output the number of lines and the filename which will cause an error. wc -l <file could be used to avoid this
for file in *.sort; do 
  if [ "$(wc -l <"$file")" -eq 57817 ]; then 
    mv "$file" "../$file"
  fi
done
0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.