简体   繁体   中英

Bash script and whitespaces in file names

I'm having a problem with filenames having whitespace in a bash script on Mac OSX:

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!

Two things:

  1. Tilde ( ~ ) does not expand in quotes; use $HOME instead if you want to use it that way.
  2. If you want to use tilde then only ${name} should be double-quoted (to prevent word-splitting).

So that would look like this ( 1 ):

"$HOME/Library/Audio/Plug-Ins/Components/${name}".component au

Or like this ( 2 ):

~/Library/Audio/Plug-Ins/Components/"${name}".component au

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM