Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Mon 22 Dec 2014, 18:15
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
executing .sh scripts inside another .sh script
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [3 Posts]  
Author Message
tatamata

Joined: 02 May 2010
Posts: 63

PostPosted: Tue 08 Jan 2013, 05:57    Post subject:  executing .sh scripts inside another .sh script  

Hello.
There is an script1.sh which executes other .sh scripts in this way:
./dir1/dir2/script2.sh
./dir1/dir3/script3.sh

This was for Ubuntu or such linux systems where you don't have to explicitely do: sh scrip.sh....

So, I tried with
sh ./dir1/dir2/script2.sh
sh ./dir1/dir3/script3.sh
but this doesn't work

I can go with
cd ./dir1/dir2/
script2.sh
cd ..
cd..
cd ./dir1/dir3/
sh script3.sh
but, obviously this is bad way to do it.

Is there a better way, in order not to go with cd?
Back to top
View user's profile Send private message 
Bruce B


Joined: 18 May 2005
Posts: 11131
Location: The Peoples Republic of California

PostPosted: Tue 08 Jan 2013, 07:32    Post subject:  

the script files will run the interpreter in the SHELL= variable unless otherwise specified.

sh is not Puppy's default, bash is

the first line of the .sh file should look like this
#!/bin/sh

the file itself needs to have, or should have the executable bit set, typically I do it like this

chmod 755 shell.sh

If you put the file in a directory in the PATH= statement, all you need to is say its name to run it

echo $PATH shows the directories which are set. It might have this directory /root/bin, if so, that would be a good place to put your toys

Quote:
So, I tried with
sh ./dir1/dir2/script2.sh
sh ./dir1/dir3/script3.sh
but this doesn't work


Do not ./dir1, the ./ makes it a relative path and it will only run if the script1.sh is ran from the parent directory

Put script2 and script3 in the path and all script1 needs to say is:

Code:
#!/bin/sh
script2.sh
script3.sh


If you don't have script1 and script2 in the path, then use full path to each, like this

Code:
#!/bin/sh
/truepath_to/script2.sh
/truepath_to/script3.sh


You don't need the .sh extension. Using it will primarily make it easier for you to recognize which type of script it is.

I've never actually wrote a script using sh or tested any of my advice, but I wanted to make sure you got some kind of help, and I think my advice is accurate, if not it will make for critique from someone and I can learn more.

~

_________________
New! Puppy Linux Links Page
Back to top
View user's profile Send private message 
L18L

Joined: 19 Jun 2010
Posts: 2621
Location: www.eussenheim.de/

PostPosted: Tue 08 Jan 2013, 08:52    Post subject: Re: executing .sh scripts inside another .sh script  

tatamata wrote:
...
So, I tried with
sh ./dir1/dir2/script2.sh
sh ./dir1/dir3/script3.sh
but this doesn't work...


I have been trying too.
... and it works Wink

my console wrote:
# pwd
/root/my-applications/bin
# ls dir1
dir2 dir3
# cat dir1/dir2/script2.sh
#!/bin/sh
echo hi this is $0
# cat script1.sh
#!/bin/sh
./dir1/dir2/script2.sh
./dir1/dir3/script3.sh
#
# script1.sh
hi this is ./dir1/dir2/script2.sh
hi this is ./dir1/dir3/script3.sh
#
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [3 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0468s ][ Queries: 12 (0.0034s) ][ GZIP on ]