I'm trying to recreate a .bat
file in a Mac environment. I want an executable file that will navigate to a directory and carry out some steps.
I have created build-env.sh
and made it executable using chmod +x build-env.sh
. But the script can't seem to properly navigate to a directory location, which is the first step. I've stripped it down so that this is currently the entire contents of the script:
echo $(pwd)
cd ~/Desktop
echo $(pwd)
In the Terminal, I navigate to the directory where the file is located, and I enter ./build-env.sh
. When I run this from the Terminal, the output I receive is:
/Users/XXX/Desktop/scripts/python/myfolder
: No such file or directory /Users/XXX/Desktop
/Users/XXX/Desktop/scripts/python/myfolder
I have searched online but come up empty. I've tried so many variations of filepaths after the "cd" (full paths, partial paths, text strings, etc.) but nothing works. Every time, the Terminal reads "No such file or directory."
To be clear, I have no problem navigating to directories when manually using the Terminal. If I copy the location that "doesn't exist" and paste it in after "cd", it works fine.
I have also tried assigning the path to a variable as below. Took these lines from an answer on this post, added them to the end of the script file, and made the same iterations (full/partial/string/etc.) on the variable.
DIR=~/Desktop
if [ -d "$DIR" ]; then
echo "yes"
fi
if [ ! -d "$DIR" ]; then
echo "NO"
fi
This doesn't result in any change. Neither "yes" nor "NO" are incorporated into the output.