Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Command not found error when i use shell command in a function

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

./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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading