I am attempting to perform the following operation:
Init state:
|--- Foobar Project
|--- Foobar.file
|--- My Projects
|--- mainfolder 1
| |--- subfolder 1
| |--- subfolder 2
|
|--- mainfolder 2
| |
| |--- subfolder 1
| |--- subfolder 2
After script:
|--- Foobar Project
|--- Foobar.file
|--- My Projects
|--- mainfolder 1
| |--- mainfolder 1 Project <----
|--- mainfolder 1.file <----
| |--- subfolder 1
| |--- subfolder 2
|
|--- mainfolder 2
| |--- mainfolder 2 Project <----
| |--- mainfolder 2.file <----
| |--- subfolder 1
| |--- subfolder 2
These steps involve first copying the Foobar Project folder into each directory within My Projects, then renaming it to the parent name.
I have this current work in progress script, but I believe I am running into the problem of handling white space characters
From My Projects folder:
for d in */; do
cp -R ../Foobar\ Project "$d";
mv -- "./$d\Foobar Project\" "./$d/$d Project\";
done
I do not currently have anything written for renaming the Foobar.file as I am stuck on renaming the folder first.
The problem I am facing is that the whitespace characters in the mv command are (I believe?) being treated as separate inputs, despite being in the same quotation marks. I am therefore a little lost as I have attempted to do trimming solutions with sed but I keep running into issues with the mv command not responding properly. I appreciate if someone knows a better way to approach this solution as I feel there is an easier way to achieve this.