Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I wrote the script below to find the number of PDF files in a given directory. However, it instead shows all the files in the directory:

#!bin/bash
message="."
message1="*.pdf"

ls -al $message $message1 

What's wrong with the script?

share|improve this question
3  
Since you appear to be using bash, I'll refer you to this method of counting the number of files in a directory. Any approach that uses ls is very likely to be non-portable and incorrect, so I'd advise against going down that road. –  jw013 Dec 21 '11 at 8:14

1 Answer 1

Because this is what the ls command should do. Your script effectively runs

ls -al . *.pdf

And that will list all the files in current directory (as specified by .). Leave out the dot and you'll have just the PDFs.

share|improve this answer
    
Thanks a lot rozcietrzewiacz –  user13522 Dec 21 '11 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.