4

I have a simple bash script running on OS X that removes specific files and directories and copies new ones in their place. One Mac .app directory contains a space, and when I run the script there is a "No such file or directory" error.

Here is the relevant code. A good amount has been cut out, so simply hard coding these differently isn't possible (the variables must be broken up as they are):

CP="cp -Rf"

INSTALL_DIR="/Applications/"

APP="The App.app"

NEWAPP="$HOME/Downloads/The App.app"

$CP "$NEWAPP " "$INSTALL_DIR$NEWAPP"

I've tried escaping The\ App.app with no luck, as well as trying single quoting, double quoting, and double escaping, but nothing has worked. I imagine there is a simple way to do this.

Thanks for your help.

nick
  • 221
  • 2
  • 3
  • 8

2 Answers2

5

You have an extra space there, it's simply

"$NEWAPP"

Karoly Horvath
  • 94,607
  • 11
  • 117
  • 176
  • Wow, that was an artifact from a previous change, and I didn't notice. Changing this definitely fixed some of the problems, as well as emergence's comment below. Thanks to both of you. – nick Jul 27 '11 at 18:01
-2

enclose the whole final line in quotes:

"$CP $NEWAPP $INSTALL_DIR$NEWAPP"

it's unnecessary to keep opening and closing the quotes here, and the $CP must be contained in quotes as CP has a space in it.

emergence
  • 405
  • 3
  • 10
  • 4
    nope. that actually tries to execute a command whose name is all the variables substituted. also, cp in quotes will try to execute the command whose name is "cp -Rf". everything in quotes is interpreted as one element. first element is the name of the command, the rest are the parameters. – Karoly Horvath Jul 27 '11 at 17:47
  • 2
    you're right, sorry. the final $NEWAPP should be $APP however or it's going to try and append $HOME/Downloads again. – emergence Jul 27 '11 at 17:54
  • emergence -- your comment is correct; I didn't notice that I had written NEWAPP vs APP. This, combined with removing the space, seemed to wrok fine. Two stupid errors working together. Thanks for the help. – nick Jul 27 '11 at 18:03