Whitespaces mistake while dealing files

my demands is to replicate all files and also folders of a "master" folder right into all the usb keys placed.

So, i created this code :

for usb_key in `ls /media/`;
    do
        for file in `ls -a /home/daniele/USB/MASTER`;
            do
                cp /home/daniele/USB/MASTER/"$file" /media/$usb_key/"$file"
            done;
    done;

for usb_key in `ls /media`;
    do
        umount /media/$usb_key
    done;
#alert me that the work is done
totem /home/daniele/USB/0016.mp3 &
exit

But, if i have actually a folder called "DO NOT DELETE" right into /home/daniele/USB/MASTER, this toss a mistake becose of the filenames.

So, just how can i do address that? There is a means to change all the whitespaces in the $file var with \?

0
2019-12-02 03:10:44
Source Share
Answers: 1

What concerning this? I do not recognize why you need to iterate each documents and also why you can not simply replicate the whole lot ... But this needs to function a little far better than by analyzing ls is result.

for usb_key in /media/*;
do
    cp -Ra /home/daniele/USB/MASTER/* $usb_key
    umount /media/$usb_key
done;

#alert me that the work is done
totem /home/daniele/USB/0016.mp3 &
exit

Just to clarify what is taking place, for breaks on all rooms when analyzing exterior input (as it was with your code). You can see that in procedure by mosting likely to a directory site with spaced documents in and also running :

for file in `ls -1`; do echo $file; done

In my TELEVISION directory site, I see result like :

The
Big
Bang
Theory
The
Cleveland
Show
The

I assume there is a means to transform the break series yet it is simply less complicated to make use of celebration is indigenous documents - searching for syntax. Or make use of find ... -exec ... which is really effective itself.

0
2019-12-03 05:03:13
Source