LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-29-2010, 05:28 AM   #1
ionrivera
Member
 
Registered: May 2010
Distribution: Debian, RHEL, AIX, Solaris, HP-UX
Posts: 61

Rep: Reputation: 4
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..

Last edited by ionrivera; 09-29-2010 at 05:29 AM.
 
Old 09-29-2010, 05:32 AM   #2
quanta
Member
 
Registered: Aug 2007
Location: Vietnam
Distribution: RedHat based, Debian based, Slackware, Gentoo
Posts: 724

Rep: Reputation: 100Reputation: 100
Code:
. /$HOME/scripts/backup.sh
There is a space between dot and slash.
 
Old 09-29-2010, 05:42 AM   #3
mardi
LQ Newbie
 
Registered: Sep 2010
Location: Indonesia
Distribution: RedHat
Posts: 16

Rep: Reputation: 3
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
 
Old 09-29-2010, 05:49 AM   #4
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,256

Rep: Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686Reputation: 2686
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.
 
Old 09-29-2010, 05:55 AM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,241

Rep: Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325Reputation: 2325
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
 
Old 09-29-2010, 07:59 PM   #6
ionrivera
Member
 
Registered: May 2010
Distribution: Debian, RHEL, AIX, Solaris, HP-UX
Posts: 61

Original Poster
Rep: Reputation: 4
Thanks for your help guys! well appreciated!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
My BASH script work perfect when i run it manualy, but not when it run in the crontab roqarg Linux - Newbie 30 05-06-2010 02:37 PM
export call in bash script Donald1000 Linux - Software 10 03-12-2009 09:03 PM
Bash script - call xterm and run in it. musther Programming 2 02-08-2008 08:57 PM
Asking a C program to call a bash script sceadu Programming 4 07-28-2005 09:52 PM
how to run a script on subfolder file in a folder saggi_sam Linux - Newbie 5 07-13-2005 06:04 AM


All times are GMT -5. The time now is 10:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration