LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   How to call another bash script to run on a subfolder? (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-call-another-bash-script-to-run-on-a-subfolder-835133/)

ionrivera 09-29-2010 04:28 AM

How to call another bash script to run on a subfolder?
 
I want my bash script to run scripts located on a different folder. If it is also located on the same folder with my script, it will go like this:

on my $HOME folder: (this_script.sh, backup.sh, restore.sh, purge.sh)

#!/bin/bash
./backup.sh
./restore.sh
./purge.sh

But what if, on my $HOME folder: (this_script.sh)
$HOME/scripts folder: ( backup.sh,restore.sh, purge.sh )

Below doesn't work...
#!/bin/bash
./$HOME/scripts/backup.sh

what the proper script for this? thanks in advance..

quanta 09-29-2010 04:32 AM

Code:

. /$HOME/scripts/backup.sh
There is a space between dot and slash.

mardi 09-29-2010 04:42 AM

You can try this if you want to specify interpret the script with specific shell. for example bash shell
Quote:

/bin/bash /$HOME/scripts/backup.sh
Regards,
Mardi V. Tamma

grail 09-29-2010 04:49 AM

The dot is merely a reference to where you are. All executable files not in your PATH need to be specified via the path to the script / executable:
Code:

/bin/bash

/usr/bin/awk

./my_script.sh

~/my_script.sh (may not work on some systems due top how tilde is expanded)

/home/name/my_script.sh

All of the above will run the chosen file.

chrism01 09-29-2010 04:55 AM

You don't need ./$HOME.

If you are in $HOME
Code:

scripts/backup.sh
If you want to call it from anywhere, specify the full path
Code:

$HOME/scripts/backup.sh
Ensure that being called from random dirs doesn't confuse the script itself.
You might want to consider cd'ing to a known dir at the start of the script.
NB: the 2nd example only works if you are logged in as the correct user (ie owner of $HOME).
Otherwise, use a specific full path eg
Code:

/home/user1/scripts/backup.sh

ionrivera 09-29-2010 06:59 PM

Thanks for your help guys! well appreciated!


All times are GMT -5. The time now is 02:49 PM.