Unix shell:在遍历目录时如何处理带有 space 的文件名?
Unix shell: how to deal with filename with space while looping through the directory?
假设在一个目录下有两个文件
file1.jpg
file 2.jpg
这是我循环遍历文件的代码:
for i in $dir/*
do
type=`exiftime -tg $i | cut -c-5`
done
我遇到的问题是,当循环查看 "file 2.jpg" 时,由于 space、"file" 和“2.jpg”,它会将其视为两个文件。我如何才能将文件视为一个文件?
用双引号将 $i
括起来:"$i"
假设在一个目录下有两个文件
file1.jpg
file 2.jpg
这是我循环遍历文件的代码:
for i in $dir/*
do
type=`exiftime -tg $i | cut -c-5`
done
我遇到的问题是,当循环查看 "file 2.jpg" 时,由于 space、"file" 和“2.jpg”,它会将其视为两个文件。我如何才能将文件视为一个文件?
用双引号将 $i
括起来:"$i"