我想遍历文件列表而不关心文件名可能包含哪些字符,因此我使用由空字符分隔的列表。该代码将更好地解释事情。
# Set IFS to the null character to hopefully change the for..in
# delimiter from the space character (sadly does not appear to work).
IFS=$'\0'
# Get null delimited list of files
filelist="`find /some/path -type f -print0`"
# Iterate through list of files
for file in $filelist ; do
# Arbitrary operations on $file here
done
以下代码在从文件中读取时有效,但我需要从包含文本的变量中读取。
while read -d $'\0' line ; do
# Code here
done < /path/to/inputfile