Bash script and whitespaces in file names

#1

Hi guys,

I’m having a problem with filenames having whitespace in a bash script:

name="My File" #file name
version="1.0.0"

echo "Copying AAX..."
mkdir aax/
cp -R "/Library/Application Support/Avid/Audio/Plug-Ins/""${name}".aaxplugin aax

echo "Copying AU..."
mkdir au/
cp -R "~/Library/Audio/Plug-Ins/Components/""${name}".component au

echo "Copying VST2..."
mkdir vst/
cp -R "~/Library/Audio/Plug-Ins/VST/""${name}".vst vst

It goes perfectly fine with the AAX file, but it won’t find the file for AU and VST. I tried quoting different parts of the command lines, but I always get “no such file or directory” for those two.

What’s wrong there?

Thanks!

#2

Replace ~ with $HOME and it should work, ~ is not expanded when inside quotes

3 Likes
#3
15:22 $ ls "~/"
ls: ~/: No such file or directory
15:22 $ ls "$HOME/"
Applications			Library

The old adage is true, you really do “learn something new every day”

#4

Thanks. I didn’t know that the tilde wouldn’t expand if quoted. Now it works as expected.