Search code examples
xcodebuildwhitespacecprun-script

How to specify a folderpath containing spaces in an environment variable that will be passed to cp in the run script build phase in Xcode?


I have the following line in a script I am running in the "Run Script" build phase in my Xcode project:

cp -v "/Users/myusername/Desktop/foo2Texture5.png" $BACKGROUND_TEXTURES_FOLDER_PATH

$BACKGROUND_TEXTURES_FOLDER_PATH is defined as a "User defined setting" in the build settings for my project. This path is generated by combining other variables / user settings etc.

The problem is, that the cp command tends to fail when the folder path contains a "space". But since the folder path is generated by combining other variables, how can I "escape" the path, so that cp reads the variable properly?

echo seems to output the variable correctly --> So it doesn't seem to have a problem with the space.


Solution

  • You need to surround the entire environment variable with quotes.

    Like : "$BACKGROUND_TEXTURES_FOLDER_PATH"