-1

I am having some issues with running a shell script within an interactive prompt. The entire code works fine and if I replace the bash script with an echo 'hello world' line it works without any issues. I am not a long time experienced user of using the shell so I would appreciate it any answer that comes with an explanation.

So basically what I am trying to do is to have an interactive shell script prompt me if I want to commence running another script to start backing up my data.

I have tried running the main script (bash my_script.sh) using the bash command and i get the following error.

main_backup_pend.sh: line 17: bash: command not found

Where line 17 is where i call the bash script seen below...

[Yy]* ) echo 'Copying database...'; bash $PATH/backup.database.sh > backup.log.$DATE.database; break;; 

#!/bin/bash

PATH=/data/sjamal/4.Backups
DATE=170317

#[COPY]Mysqldump, making database copy storing it locally

    while true; do
    read -p "Do you wish make a database copy?" yn
    case $yn in
        [Yy]* ) echo 'Copying database...'; bash $PATH/backup.database.sh > backup.log.$DATE.database; break;;
        [Nn]* ) break;;
        * ) echo "Please answer yes or no.";;
    esac
done

#[BACKUP]Performing back up of Repository to HPC

    while true; do
    read -p "Do you wish to back up Repository to HPC?" yn
    case $yn in
        [Yy]* ) echo 'backing up Repository...'; bash $PATH/backup.Repository.sh > backup.log.$DATE.repository; break;;
        [Nn]* ) break;;
        * ) echo "Please answer yes or no.";;
    esac
done
1

The first line of your script breaks everything:

PATH=/data/sjamal/4.Backups

What this tells your script is that all its commands - including the bash interpreter itself - live exclusively in this directory. (Perhaps you didn't know that PATH is a reserved variable? Try echo $PATH sometime to see the list of directories that are usually searched for commands.)

Change your use of PATH throughout the script to something else, perhaps backup_dir and it's more likely to work as expected.


Other hints: put your variables (and paths using variables) in "$double_quotes" when you use them. So instead of backup.log.$DATE.repository use "backup.log.$DATE.repository".

  • Oh of course! I feel so stupid to have missed that. The error message had me doubting completely different things. – S.Jamal Mar 20 '17 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.