So I'm trying to make a simple script that takes a source dir, and a destination dir as arguments, and creates an identical directory structure at the destination, then converts every file in the source, and puts it in the corresponding destination directory using the GNU parallel command.
My script looks like this:
#!/bin/bash
SOURCE=$1
DEST=$2
find $SOURCE -type f -name '*.flac' -printf "%P\n" | parallel --dry-run mkdir -p $DEST{//}
find $SOURCE -type f -name '*.flac' -printf "%P\n" | parallel --dry-run ffmpeg -loglevel info -i {} -codec:a libmp3lame -qscale:a 3 $DEST{/.}.mp3
Huzzah! The mkdir works as expected (yes, mkdir will try to make a directory for every file, and I'm OK with that, for now).
However, on the ffmpeg line, the output doesn't end up at $DEST. In fact, it appears that the $DEST is null, as it doesn't show up in my --dry-run output.
So as I was writing this, I had a thought, and used this simplified replacement for the ffmpeg line just to play around with it:
find $SOURCE -type f -name '*.flac' -printf "%P\n" | parallel --dry-run echo {} $DEST{/.}.mp3
The same behavior was seen. Cool. Then I moved where $DEST is, like this:
find $SOURCE -type f -name '*.flac' -printf "%P\n" | parallel --dry-run echo {} {$DEST/.}.mp3
And amazingly, moving the $DEST inside the {/.} works! However, trying the same trick in the MKDIR case, like {$DEST//}, doesn't work.
So why does the MKDIR case only work using $DEST{//}, and the simplified case only work using {$DEST/.}?
Thanks!