user116064
user116064

Reputation: 87

Unix shell: how to deal with filename with space while looping through the directory?

Suppose in a directory there are two files

file1.jpg 
file 2.jpg

Here's my code to loop through the file:

for i in $dir/*
do 
   type=`exiftime -tg $i | cut -c-5`
done

The issue I have is when the loop looks at "file 2.jpg", it treats it as two files because of the space, "file" and "2.jpg". How do I get it to treat the file as one file?

Upvotes: 0

Views: 73

Answers (1)

milind brahme
milind brahme

Reputation: 113

Enclose $i in double quotes: "$i"

Upvotes: 4

Related Questions