在bash脚本字符串连接 [英] string concatenation in bash script
本文介绍了在bash脚本字符串连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写这Bash脚本:
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
这个脚本是concate部分字符串转换成字符串时,该值除以4,它应该是大于0。
The script is to concate part strings into a string when the value is divided by 4 and it should be larger than 0.
在IMAGE_DIR,我有8个图像,
In the IMAGE_DIR, I have 8 images,
我得到了这样的输出:
abc et004.jpg
abc et008.jpg
但我希望有:
abc et001.jpg et002.jpg et003.jpg et004.jpg;
abc et005.jpg et006.jpg et007.jpg et008.jpg;
有谁请帮我解决这个问题?
Could anybody please help me to fix this problem?
在此先感谢。
推荐答案
这样呢?
count=0
find $IMAGE_DIR -name "*.jpg" |
while read f; do
if (( (count % 4) == 0 )); then
result="abc $f"
if (( count > 0 )); then
echo $result
fi
else
result="$result $d"
fi
(( count++ ))
done
这篇关于在bash脚本字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文