VectorLinux
April 17, 2014, 09:54:39 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: calling functions in other files  (Read 3414 times)
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« on: August 06, 2009, 04: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?
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
brokndodge
Member
*
Posts: 83


Linux is sooo HOT


WWW
« Reply #1 on: August 06, 2009, 05: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:
#! /bin/bash

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

functioncall

Logged

VL 7.0 Standard

brokndodge
- OSS is not a religion, it's the solution to buggy irresponsible coding -
Linux User# 494720
Daniel
Packager
Vectorian
****
Posts: 704


WWW
« Reply #2 on: August 06, 2009, 05:41:33 pm »

Thanks! Using the include statement thing worked!
Logged

The following sentence is true. The previous sentence is false.

VL 6.0 SOHO KDE-Classic on 2.3 Ghz Dual-core AMD with 3 Gigs of RAM
M0E-lnx
Administrator
Vectorian
*****
Posts: 3134



« Reply #3 on: August 07, 2009, 03:44:53 am »

The actual commamd is 'source' in bash. The . Is a shortcut for it
Logged

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!