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?