Pay attention to the error message in the output. You have a syntax mistake in line 14. There can be no spaces around the equals sign when setting a variable.
And again as I cautioned, quote all variable expansions unless you want word-splitting to occur. This is doubly true inside
[..] tests. Consider using bash's more advanced
[[..]] test operator instead, which doesn't do word-splitting on variables.
"
$@" should almost always be quoted too, which will act as if each expanded element is quoted separately. But as I also pointed out, you don't need to use it at all when feeding a
for loop.
When doing
purely arithmetical operations and comparisons on
integers, don't use
expr, use
$((..)), or
((..)) when no output is required. Things get more complex if you have floating point numbers, as bash can't handle them internally. Then you have to use an external tool like
bc or
awk.
Note also the
$ isn't needed for variables inside arithmetic fields. All non-integer/non-math strings will be automatically interpreted as variables.
To alter your code, you need to get the file size from somewhere and test that. I recommend
stat.
Finally, you should get into the habit of using a clean indentation and formatting style, and use liberal comments. Scripts are much easier to debug when they're easily readable.
Here's an example with my suggested modifications.
Code:
#!/bin/bash
# loop through each parameter given
for dir ; do
#preset the counter to zero
total=0
# first test if it's a directory
if [[ -d $dir ]] ; then
# then loop through each name in the directory
for file in "$dir"/* ; do
# if the name is a file, and over 1000 bytes
# print the name and increment the counter
if [[ -f $file && $( stat -c %s $file ) -gt 1000 ]] ; then
echo "$file"
(( total = total + 1 ))
fi
done
fi
# print the total number of files at the end, and an empty separator line.
echo "total files : $total"
echo
done
Of course I'm really only doing this for educational purposes. For real work, something using
find like NA's code above would probably be more useful.