[Bash] Counting files
I'm making a script that's supposed to do different things depending of how many files there is in a folder that starts with ref.
I've tried to do a count with this for-loop: Code:
for file in $dir/ref* Thanks a lot in advance! |
i havent done any linux scripting in quite a long time, but instead of using the hardcoded string "$dir/ref*", can you run a command and save the output? something like:
Code:
for file in `ls $dir/ref*` edit: note that above ` are "backticks" not single quotes. |
Works like a charm. Thanks a lot!! :)
|
Try
Code:
shopt -nullglob |
Following the suggestion by nadroj above, you can use the ls command, but you don't really need a loop if you do something like:
Code:
ls $dir/ref* 2> /dev/null | wc -l Code:
nfiles=$(ls $dir/ref* 2> /dev/null | wc -l) |
All times are GMT -5. The time now is 06:32 AM. |