for loop through files with spaces and some specia

2019-01-29 13:53发布

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

3条回答
The star\"
2楼-- · 2019-01-29 14:06

I accomplished this using the following command

find -name '*.eml' | while read email; do cat "$email" | ./locatePipe.php; done
查看更多
太酷不给撩
3楼-- · 2019-01-29 14:24

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

shopt -s globstar
for i in **/*.eml; do
    cat "$i"
done | ./locatePipe.php
查看更多
成全新的幸福
4楼-- · 2019-01-29 14:28

Use the -exec option

find -name '*.eml' -exec cat {} + | ./locatePipe.php
查看更多
登录 后发表回答