My script doesn’t work if the directory ($bron) is with white spaces
how can i prevent this?
the goal is to copy all files of a flash card to computer over usbmass
used code:
bron='/Harddisk/Data/disk 1'
n=0
for img in `find "$bron/DCIM" -name '*.*'`
do
filename=$(basename "$img")
n=$((n+1))
qdbus $qdbusRef setLabelText "Bezig met "$filename" ($n van $numfiles)"
qdbus $qdbusRef Set org.kde.kdialog.ProgressDialog value $n
cp -a -u "$img" "$doel/$project"
done
chmod -R 777 "$doel/$project"
qdbus $qdbusRef close
exiftool -d %Y-%m-%d_%f.%%e "-filename<CreateDate" "$doel/$project"
output from terminal:
+ for img in '`find "$bron/DCIM" -name '\''*.*'\''`'
++ basename /Harddisk/Data/disk
+ filename=disk
+ n=1
+ qdbus org.kde.kdialog-4453 /ProgressDialog setLabelText 'Bezig met disk (1 van 4)'
+ qdbus org.kde.kdialog-4453 /ProgressDialog Set org.kde.kdialog.ProgressDialog value 1
+ cp -a -u /Harddisk/Data/disk '/Harddisk/Data/disk 2/2013-04-09'
cp: kan status van ‘/Harddisk/Data/disk’ niet opvragen: Bestand of map bestaat niet
+ bron='/Harddisk/Data/disk\ 1'
+ cd '/Harddisk/Data/disk\ 1'
/usr/local/bin/usbcamera: regel 73: cd: /Harddisk/Data/disk\ 1: Bestand of map bestaat niet
+ n=0
++ find '/Harddisk/Data/disk\ 1/DCIM' -name '*.*'
find: `/Harddisk/Data/disk\\ 1/DCIM': Bestand of map bestaat niet
The reason there is a problem isn’t because of the ‘find’ command (which
was what I incorrectly tried to fix) but because the ‘for’ loop is taking
output from ‘find’ delimited by spaces (escapes not counted). I think
nrickert’s response is probably closer to the fix than mine was.
> The reason there is a problem isn’t because of the ‘find’ command (which
> was what I incorrectly tried to fix) but because the ‘for’ loop is
> taking output from ‘find’ delimited by spaces (escapes not counted). I
> think nrickert’s response is probably closer to the fix than mine was.
>
> Good luck.
Ah, that’s what I get for not reading quite as closely as I thought I
had.
thx to everyone, found a solution with the help from here
gebruiker=`whoami`
bron='/var/run/media/$gebruiker/NIKON D5000'
cd "$bron"
for img in `ls -d DCIM/*/*`
do
filename=$(basename "$img")
n=$((n+1))
qdbus $qdbusRef setLabelText "Bezig met "$filename" (Foto $n)"
qdbus $qdbusRef Set org.kde.kdialog.ProgressDialog value $n
cp -a -u "$img" "$doel/$project"
done