I am relatively new to bash and am having some trouble with a script I am trying to write. After spending the last hour or so researching and trying new techniques, I am still unable to do what I would like.
My goal is this: I have a folder /Volumes/Server\ RAID/Photos
where I keep all of my pictures. Each folder is titled YYYY-MM FolderName
where there are sometimes spaces in FolderName
. Within these folders are three folders: Raw
, Edited
, and Final
. My goal is to, with a single bash script, create symbolic links on my Desktop for each Final
folder AND rename it to its parent folder. Example: I would like /Volumes/Server\ RAID/Photos/2016-10\ Fleet\ Week/Final
to have a symbolic link on the Desktop named 2016-10 Fleet Week
.
I have tried many different varieties of the code I have posted down below, but the code I have included was the most concise code (although it didn't work).
Code description:
- cd to Desktop so that symlinks are created there
- use for loop to loop through folders
- create symlink - here is the problem: I need to include the folder name in the file path somehow, but also add
\
before the spaces so that the command doesn't fail. HOWEVER, I have been getting error messages saying that there is no place calledRAID/Photos
which makes me think the script is stumbling on the first space, even with the backslash. Change name of
Final
symlink to the folder name. (I assumed I didn't need full directories here because I'm already in Desktopcd Desktop for f in /Volumes/Server\ RAID/Photos; do ln -s /Volumes/Server\ RAID/Photos/"$f"/Final mv Final $f done
QUESTION: Can someone please help me flush out this script? (I am mainly concerned with part three, but I wouldn't say no to help with the rest of it, either).
$f
in the mv command. Even if it is properly escaped when put into the variable, it will expand into multiple words when you use it without quoting.