If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Calling of one script from another script

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-10-08, 10:39
jayawant01 jayawant01 is offline
Registered User
 
Join Date: Jun 2008
Posts: 40
Calling of one script from another script

Hi all,
I m very new to shell scripting .Kindly bear with me if i ask too many silly questions.

My question is supposing I am calling one script inside another script
and the script which is been called has lot many functions defined in it ...

So is the entire script is called or I can invoke any selective part of the script and come back to my org script , if this is possible how can i identify how it goes back to the parent script
Reply With Quote
  #2 (permalink)  
Old 06-10-08, 11:16
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
Best to have a file that just contains your routines. It doesn't need a #!/bin/sh at the top or an exit at the bottom and it doesn't need to be executable. I've called my file "subs" and this is the contents:
Code:
my_sub ()
{
        echo in sub 1
}

my_other_sub ()
{
        echo in sub 2
}
I've now created a script file that can use these subs. It's included in the main file by the "." command and it just includes all the code in the subs file in my main file. Obviously there might be many scripts all using this set of subs. Note I'm calling the procedures (my_sub, my_other_sub) in the main script but not defining them there. I've called my main script "my_script" and this is the contents:
Code:
#!/bin/sh

. subs

echo test a

my_sub

echo test b

my_other_sub

echo test c

exit 0
To run the script I need to make the main script executable and then call it. I've included the output.
Code:
 chmod +x my_script
 ./my_script

test a
in sub 1
test b
in sub 2
test c
Hope that helps. I wouldn't get too worked up about procedural programming while shell scripting - it is powerfull but it's not a high level language.

Mike
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On