I am writing this Bash script:
count=0
result
for d in `ls -1 $IMAGE_DIR | egrep "jpg$"`
do
if (( (count % 4) == 0 )); then
result="abc $d"
if (( count > 0 )); then
echo "$result;"
fi
else
result="$result $d"
fi
(( count++ ))
done
if (( (count % 4) == 0 )); then
echo $result
fi
The script is to concate part strings into a string when the value is divided by 4 and it should be larger than 0.
In the IMAGE_DIR, I have 8 images,
I got outputs like this:
abc et004.jpg
abc et008.jpg
But I would expect to have:
abc et001.jpg et002.jpg et003.jpg et004.jpg;
abc et005.jpg et006.jpg et007.jpg et008.jpg;
How can I fix this?
Something like this (untested, of course):
Something like this?
The
=
operator must always be written without spaces around it:(Pretty much the most important difference in shell programming to normal programming is that whitespace matters in places where you wouldn't expect it. This is one of them.)