找到包含在bash空格的文件while循环 [英] find while loop with files containing spaces in bash

查看:147
本文介绍了找到包含在bash空格的文件while循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图搜索可能包含空格我尝试使用 -print0 并设置 IFS 这里的文件是我的脚本

I try to search for files that may contain white spaces I try to use -print0 and set IFS here is my script

IFS=$'\0';find people -name '*.svg' -print0 | while read file; do
    grep '<image' $file > /dev/null && echo $file | tee -a embeded_images.txt;
done

我尽量细的嵌入式图像的所有SVG文件,它没有-print0工作,但无法一一文件,所以我停止脚本。下面是简单的例子不工作太

I try to fine all svg file containing embeded images, it work without -print0 but fail one one file so I stop the script. Here is simpler example that don't work too

IFS=$'\0';find . -print0 | while read file; do echo $file; done

它不显示任何内容。

it don't display anything.

推荐答案

使用读-d''-r文件,而不是设置 IFS

find people -name '*.svg' -print0 | while read -d '' -r file; do
    grep '<image' "$file" > /dev/null && echo "$file" | tee -a embeded_images.txt;
done

和引用您的变量。

这篇关于找到包含在bash空格的文件while循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆