Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2008

    Unanswered: 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

  2. #2
    Join Date
    Jun 2007
    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:
    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:
    . subs
    echo test a
    echo test b
    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.
     chmod +x 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.


  3. #3
    Join Date
    Dec 2013

    i am learning unix scriting so i came accross ur example as above

    i have executed in the same way the rest i get is

    when executed the ./
    bob@BOB:~/Desktop/Bash_script$ ./
    + . subs_1
    ./ 4: .: subs_1: not found

    i am using ubuntu.
    please let me know where is the fault.

  4. #4
    Join Date
    Jun 2003
    West Palm Beach, FL


    Quote Originally Posted by bob_121 View Post
    i am learning unix scriting so i came accross ur example as above
    i have executed in the same way . . . .
    . . . E t c
    No you did not.
    If you are going to follow an example, perhaps you should carefully READ it, do and apply exactly as it says.
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts