私は今、いくつかの指示に従って、いくつかのファイルをディレクトリAから複数のディレクトリBにコピーするスクリプトを作業しています。スクリプトはうまく機能しますが、スペースがあるファイルの場合は複数のファイルとして扱います。
my_super_cool_file_2007039904_11 (3rd copy).pdf
ファイルがこのループにある間:
for i in $(find $parent -mindepth 1 -maxdepth 1 -type f|cut -c 11-);do
echo "this is the file: $i"
done
複数のファイルとして扱われます。
this is the file: my_super_cool_file_2007039904_11
this is the file: (3rd
this is the file: copy).pdf
usingに変更しようとしましたが、space
問題が解決していないようです。ループの場合は3つの異なるファイルで、usingと同じ問題があり、引き続き使用する必要がありました。\space
sed 's/ /\\ /g'
ls
find
ベストアンサー1
-maxdepth 1
andを使用しているので、-mindepth 1
単純なループ(in bash
)を実行することもできます。
for name in "$parent"/*; do
if [ -f "$name" ]; then
dir=${name%/*} # dir=$( dirname "$name" )
dir=${dir##*/} # dir=$( basename "$dir" )
printf 'The directory is "%s"\n' "$dir"
fi
done
屋根の結果はfind
通常悪い習慣です。検索結果を繰り返すのはなぜ悪い習慣ですか?