Well, I got it to work, but what's really weird was that what I ended up doing was copy/pasting what I had into a new "Test.sh" file and changing the paths to something else that existed but had no spaces. It took my like two minutes to get it to work. Then, when I copied and pasted the exact same paths into my old script, it gave the same error, even though the two were identical. So all I did was rename my test script and change the paths back, and it worked.
I must have had some whitespace character that was bad for UNIX or something.
Here's the final program.
Code:
# This shell script can be used to automatically place custom HoMM V
# maps into the proper directory. In order to use it, make sure you
# change the variable hommv_path to wherever it is on your hard drive,
# and change the copy_dir to wherever you want to copy the maps from.
# Then, simply double click to open this, all maps in the copy_dir will
# be copied into the maps folder for hommv_path.
#
# This script was made by Demonpants sixleg.com steal it if you want. :-)
#
hommv_path="/Applications/Games/Heroes of Might and Magic V.app/"
move_dir="/Users/eli/Desktop/"
maps_dir="Contents/Resources/transgaming/c_drive/Program Files/Ubisoft/Heroes of Might and Magic V/"
total_dir=$hommv_path$maps_dir
folder_name="Maps/"
#
#Creates the Maps directory if needed
if [ -d "$total_dir$folder_name" ];
then
echo "Maps folder found.";
else
cd "$total_dir";
mkdir "$folder_name";
echo "New folder $folder_name created in $total_dir";
fi
#
#Moves all .h5m files from the move_dir to the Maps folder
cd "$move_dir"
for file in *.h5m;
do
mv "$file" "$total_dir$folder_name";
echo "Map $file moved to $total_dir$folder_name";
done
#
echo "All maps moved successfully."
So thanks for all the help. Oh, and one thing that should be noted is that Mac OS X conventions that work within the Terminal do not work within shell scripts. The tilde, for example (~), is supposed to link to your home directory, and typing "\ " is supposed to represent a space no questions asked. This stuff doesn't work when running from a script (or a .command file, as I changed it to later).