Highland Linux User Group

Linux Community
It is currently Mon Feb 06, 2012 9:34 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Bash script problem
PostPosted: Wed Feb 24, 2010 12:36 pm 
Offline
Moderator
User avatar

Joined: Tue Oct 03, 2006 12:27 pm
Posts: 162
Location: Inverness UK
I have a list of folders:

This_is_folder_1
This_is_folder_2
This is folder 3
....................


As you can see there are 2 types of folders, one with underscore "_" and one without.

in the system, i want to write a script operate the following:

list directories in current directory
ls -d */
go to each folder on the current list
cd ./directory1
create a second folder and mirror the name after the first name

mkdir ./directory1/directory1

do the thing that i want to do in ./directory1/ and copy to ./directory1/directory1

cp ./directory1/* ./directory1/directory1/

finish the job, go back to root directory where i started

cd ../

and follow up loop till i get to the end

done

i wrote a following bash script:
Code:
for dirs in $(ls -d */); do #list directories

        cd "$dirs" #go to directory

        mkdir "$dirs/$dirs" # create a mirror directory


        for f in *.txt; # file that i want to process

        do

           mv "$f" "$dirs/$dirs/$f" ; # move it to the mirror directory
        done
cd ../ #follow up
done


The code is working fine with folders like this This_is_folder until it gets to the folder with spaces like This is folder

the script will read the each word with space as a folder, and it will try to do

cd ./This #oops i can't find it No such file or directory
cd ./is #oops i can't find it No such file or directory
cd ./folder #oops i can't find it No such file or directory

instead of doing:


cd ./This is folder/ then mkdir ./This is folder/This is folder/

I've tried to list all of directories into a text file and read it from there and do the same thing but the same problem occurred.

Any suggestion?

_________________
Computers are like air conditioners, They stop working properly when you open Windows!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2010 Highlands Linux Users Group