1

我已经尝试了下面的示例,但它没有返回任何内容,但是如果我删除带有空格的名称,它就可以工作。如何处理带有空格的文件夹名称?

MainDir="/Users/redres/Dropbox/Computer\ Ebooks/Skimmed"

# FS=$'\n'

while IFS= read -d $'\0' -r file ; do
            printf 'File found: '"'%s'"'\n' "$file"
    done < <(find "$MainDir" -iname '*' -print0)

i=1

for i in $(find $MainDir -type f); do echo "$i"; done;

谢谢

4

2 回答 2

0

代码的格式足以让人流泪!

但是,这应该可以工作,假设在空格之前的目录名称中实际上没有反斜杠:

MainDir="/Users/redres/Dropbox/Computer Ebooks/Skimmed"

while IFS= read -d '' -r file
do
    printf "File found: '%s'\n" "$file"
done < <(find "$MainDir" -print0)

例如:

$ mkdir -p 'Double  Spaced  Directory/Holograms/Object Lesson'
$ cp /dev/null 'Double  Spaced  Directory/Holograms/Object Lesson/Obstacle Course'
$ MainDir=$PWD/"Double  Spaced  Directory"
$ while IFS= read -d '' -r file
> do
>     printf "File found: '%s'\n" "$file"
> done < <(find "$MainDir" -iname '*' -print0)
File found: '/Users/jleffler/soq/Double  Spaced  Directory'
File found: '/Users/jleffler/soq/Double  Spaced  Directory/Holograms'
File found: '/Users/jleffler/soq/Double  Spaced  Directory/Holograms/Object Lesson'
File found: '/Users/jleffler/soq/Double  Spaced  Directory/Holograms/Object Lesson/Obstacle Course'
$
于 2013-10-20T03:58:57.757 回答
0
MainDir="/Users/redres/Dropbox/Computer\ Ebooks/Skimmed"

引用空格或\-escape 它,而不是两者兼而有之。利用

MainDir="/Users/redres/Dropbox/Computer Ebooks/Skimmed"
于 2013-10-20T03:56:55.200 回答