ファイル名に含まれる文字を気にせずにファイルのリストを繰り返し処理したいので、ヌル文字で区切られたリストを使用します。コードは物事をよりよく説明します。Bashループでヌル区切り文字列を読む
# 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
次のコードは、ファイルから読み込むときに機能しますが、テキストを含む変数から読み込む必要があります。 bashで
while read -d $'\0' line ; do
# Code here
done < /path/to/inputfile
bash変数にヌル文字を格納することはできません。少なくとも、私はそれをする方法を見つけたことがありません... –