for loop through files with spaces and some special characters

99封情书 提交于 2019-11-28 13:02:47

问题


I need to run the following command with a for loop

cat Locate\ Message.eml | ./locatePipe.php

I am trying the following however it seems to break on the first space in the file name

for i in $(find -name "*.eml"); do cat $i | ./locatePipe.php; done

Some of the file names contain "@", "()", "-", ".", "[]", " ' " if that matters


回答1:


Use the -exec option

find -name '*.eml' -exec cat {} + | ./locatePipe.php



回答2:


I accomplished this using the following command

find -name '*.eml' | while read email; do cat "$email" | ./locatePipe.php; done



回答3:


If you're using bash 4, just skip using find:

shopt -s globstar
for i in **/*.eml; do
    cat "$i"
done | ./locatePipe.php


来源:https://stackoverflow.com/questions/33172934/for-loop-through-files-with-spaces-and-some-special-characters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!