Find the answer to your Linux question:
Results 1 to 4 of 4
Hi I'm having a bit of trouble with including a bash shell script within another and was hoping that someone could help? I have created a script of utility functions ...
  1. #1
    Just Joined!
    Join Date
    Feb 2010
    Location
    Raleigh, NC
    Posts
    3

    error when using "source utility_script.sh" in main_script.sh

    Hi

    I'm having a bit of trouble with including a bash shell script within another and was hoping that someone could help?

    I have created a script of utility functions that I'd like to incorporate into other scripts so that they can use the functions, but I can't get it to work.

    This is what is in the utility_script.sh

    Code:
    #!/bin/bash
    # other comments
    
    echo "inside utility script"
    
    my_utility_function()
    {
        # do stuff
        return
    }
    This is what I've done in the main_script.sh

    Code:
    #!/bin/bash
    # other comments
    
    source /full_path_to_script/backup_utils.sh
    
    my_function()
    {
        my_utility_function "params"
        return
    }
    
    my_function "params"
    The error I get is "my_utility_function: command not found", and it doesn't echo the line that shows that it is in the utility script at all.

    Please can you help me with what I may be doing wrong?

    Thanks

  2. #2
    Linux User
    Join Date
    Nov 2009
    Location
    France
    Posts
    292
    Are backup_utils.sh and utility_script.sh the same ?
    0 + 1 = 1 != 2 <> 3 != 4 ...
    Until the camel can pass though the eye of the needle.

  3. #3
    Just Joined!
    Join Date
    Feb 2010
    Location
    Raleigh, NC
    Posts
    3
    Quote Originally Posted by nmset View Post
    Are backup_utils.sh and utility_script.sh the same ?
    Yes -- sorry. I was trying to keep things simple, but copied and pasted that bit of the post. I didn't notice.

  4. #4
    Just Joined!
    Join Date
    Feb 2010
    Location
    Raleigh, NC
    Posts
    3
    OK, I have no explanation for this because I didn't do anything (except to try and run it again after lunch), but it now seems to be working.

    Thanks to everyone who looked at this.

Posting Permissions

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