I'm new to shell scripting and generally the usage of Terminal.
I recently made a script.sh
that I want to use by just typing its name without the full path.
So, I wrote the path of the directory into .zprofile
as:
export "PATH=$PATH:/path/to/scriptdirectory"
and changed the file permissions with:
% chmod +x script.sh
If I use the script with:
% sh myscript.sh
everything run smoothly as intended.
But if I try to omit the sh
and type:
% myscript.sh
the script start running its first part, which is just reading a variable, but as soon as I insert the value, the follow line pops:
/path/to/scriptdirectory/script.sh:11: = not found
This is the script:
#!/bin/zsh
echo "Do you want to set or change the backup location? (type y/n)"
read SET_BACKUP
while [ "$SET_BACKUP" != "y" ] && [ "$SET_BACKUP" != "n" ]
do
echo "Please, write y or n:"
read SET_BACKUP
done
if [ "$SET_BACKUP" == "y" ]
then
echo "Write the absolute path of the desired backup location:"
read BACKUP_FOLDER
echo "Starting backup..."
cp -R "/fileslocation" "$BACKUP_FOLDER"
echo "Backup completed."
else
echo "Starting backup..."
cp -R "/fileslocation" "$BACKUP_FOLDER"
echo "Backup completed."
fi
sh thingy.sh
it implies thatsh
(the bourne shell) is executing your script and notbash
orzsh
. Without it (and no shebang) you are using the system default (probably bash). These behave differently.#!/bin/zsh
as shebang.zsh script.sh
? Do you get the same error? Which line emits the error? I don't see a=
around the 11th line