I am pretty new to shell script. I want to make a simple script that will install my script to the system. So I have tried to the write a simple script for that. Here is my code below.
#! /bin/bash
#Purpose: It is the install script for Template.sh
#Version:1.0
#Created Date: Thu Mar 16 04:10:20 PM IST 2023
#Modified Date:
#Author: Sayantan Sinharay
# START #
installPackage() {
local PATH=$1
if [[ -f PATH/template ]]; then
cat template.sh >template
else
touch template
cat template.sh >template
chmod 777 template
sudo mv template PATH
fi
}
INSTALL_PATH="/bin/"
if [[ $# -eq 1 ]]; then
INSTALL_PATH=$1
elif [[ $# -gt 1 ]]; then
echo "ERROR: Expected 1 argument. Got $#"
exit 1
fi
installPackage INSTALL_PATH
# touch hello.sh --> These are working
# chmod +x hello.sh --> These are working
# END #
On running this I am getting an command not found error
Here is the error in the terminal
./installTemplate.sh: line 15: touch: command not found
./installTemplate.sh: line 16: cat: command not found
./installTemplate.sh: line 17: chmod: command not found
./installTemplate.sh: line 18: sudo: command not found
>Solution :
installPackage INSTALL_PATH is likely a typo – you meant installPackage "$INSTALL_PATH".
The former passes the literal string INSTALL_PATH while the latter passes the contents of the variable.