VectorLinux

Cooking up the Treats => Help Wanted-Developers => Topic started by: Daniel on August 06, 2009, 05:07:07 pm

Title: calling functions in other files
Post by: Daniel on August 06, 2009, 05:07:07 pm
(I guess this is the right place to put this)

How do you call functions from a shell script that are in files other than the shell script itself? I saw an example of this in the vasm scripts in /sbin. There is a vasm script and a vasm-functions script. At different points, vasm or a script that vasm executes call functions from the vasm-functions script such as check_root. I tried to call a function in a "functions" script (for a script that I am writing) in the (I think) the same way that the vasm script did it but I couldn't get it to work. Help?
Title: Re: calling functions in other files
Post by: brokndodge on August 06, 2009, 06:24:47 pm
post your scripts so we can take a look. 

according to http://ubuntuforums.org/showthread.php?t=664657 bash has an equivalent to c's include statement.  it's simply a . so to include functions from another file you would just do:
Code: [Select]
#! /bin/bash

# here is the include statement
. somefunctionfile.sh   #don't forget the space between the . and the filename

functioncall

Title: Re: calling functions in other files
Post by: Daniel on August 06, 2009, 06:41:33 pm
Thanks! Using the include statement thing worked!
Title: Re: calling functions in other files
Post by: M0E-lnx on August 07, 2009, 04:44:53 am
The actual commamd is 'source' in bash. The . Is a shortcut for it