I have a folder path stored in a variable ${PROJECT_DIR}. I want to navigate up into its parent folder, and back down into a folder called "Texture Packer" , i.e.. ${PROJECT_DIR} and "Texture Packer" are siblings. How do I specify it in a shell script ? So far I have:
TP=/usr/local/bin/TexturePacker
# create all assets from tps files
${TP} "${PROJECT_DIR}/../Texture Packer/*.tps"
But this is incorrect, since Texture Packer can't detect the files in the path. The error message displays:
TexturePacker:: error: Can't open file /Users/john/Documents/MyProj/proj.ios_mac/../Texture Packer/*.tps for reading: No such file or directory
EDIT: The following seems to work but isn't clean:
#! /bin/sh
TP=/usr/local/bin/TexturePacker
if [ "${ACTION}" = "clean" ]
then
# remove sheets - please add a matching expression here
# Some unrelated stuff
else
cd ${PROJECT_DIR}
cd ..
cd "Texture Packer"
# create all assets from tps files
${TP} *.tps
fi
exit 0
You're on the right track; the problem is that wildcards (like *.tps
) don't get expanded when they're in quotes. The solution is to leave that part of the path outside of the quotes:
${TP} "${PROJECT_DIR}/../Texture Packer"/*.tps
BTW, I almost always recommend against using cd
in scripts. It's too easy to lose track of where the current directory will be at various points in the script, or have an error occur and the rest of the script runs in the wrong place, or... Also, any relative pathis you're using (e.g. those supplied by the user as arguments) change meanings every time you cd
. Basically, it's an opportunity for things to go weirdly wrong.