Ubuntu – Can’t run Bash script


I am trying to run a simple Bash script called deploy-site.sh (by http://klau.si/dev). I made the necessary edits to run it locally (change of WORKDIR, etc). I also followed the instructions here.

mkdir ~/bin
chmod 755 ~/bin

(To store the script in my home folder. Then I rebooted, so the system recognizes it.)

sudo chmod +x <path>
sudo chmod 755 <filename>

However, whenever I go to the terminal to execute the Bash script, I get:

$ sudo deploy-site.sh <sitename>
sudo: deploy-site.sh: command not found

How can I fix this problem?

Here is the original script:


if [[ $# -lt 1 || $1 == "--help" || $1 == "-h" ]]
  echo "Usage:"
  echo "  sudo `basename $0` SITENAME"
  echo "Examples:"
  echo "  sudo `basename $0` drupal-8"


echo "<VirtualHost *:80>
    ServerAlias $1.localhost
    DocumentRoot $WORKDIR/$1
    <Directory \"$WORKDIR/$1\">
        Options FollowSymLinks
        AllowOverride All
        Require all granted
</VirtualHost>" > $APACHEDIR/$1.conf
a2ensite $1
service apache2 restart
grep -q "  $1.localhost" $HOSTSFILE
if [ $? -ne 0 ]; then
  echo "  $1.localhost" >> $HOSTSFILE

As requested, here is the results of echo $PATH


Best Answer

deploy-site.sh is not in PATH. You have to run it as ./deploy-site.sh if you are in the same directory or /path/deploy-site.sh if not

Related Question