0

I am writing a shell script, and need to include some validation. My validation is checking the backup folder exists, with the correct number of files present inside it.

For example, if the backup ran successfully then there would be 23 files in the backup folder, and we can continue. I am having some problems with my script - can anyone see any my script does not work?

if [ 'ls -1 | wc -l' == 23 ]
then
    echo -e "\n Matching! \n"
else
    echo -e "\n Something has gone wrong!\n" 
fi
Dustin Cook
  • 1,215
  • 5
  • 26
  • 44

1 Answers1

2

In your condition, you are using single quotes (') where you actually meant to use backticks. You can use the $(..) which is preferred over backticks:

if [ $(ls -1 | wc -l) == 23 ]

See also:

What's the difference between $(command) and backticks

Community
  • 1
  • 1
P.P
  • 117,907
  • 20
  • 175
  • 238