Call external function


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Call external function
# 1  
Old 04-01-2011
Call external function

Is it possible to call a function from another script?

Thanks
# 2  
Old 04-01-2011
Sort of.
Code:
# file1
foo()
{
    echo "foo was called"
}

Code:
#file2  
# source file1
. file1
# call the any function in file1
foo


Last edited by jim mcnamara; 04-01-2011 at 02:16 PM..
# 3  
Old 04-01-2011
Great thanks very much
# 4  
Old 04-08-2011
Lets say I have two scripts A and B.

Script A is using a function in B

So I use . scriptB to get access to all functions.

This works fine if I run scriptA in directory that scriptB is in, but it does not seem to work if I run it in another directory?
# 5  
Old 04-08-2011
create an absolute path. assume scriptB live in /home/chrisj
Code:
.  /home/chrisj/scriptB

# 6  
Old 04-08-2011
Source scriptB using its full pathname.
Code:
. /path/to/scriptB

# 7  
Old 04-08-2011
Thanks stating full path works fine
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Problem in passing date to external function from perl script.

my $sysdate = strftime('%Y-%m-%d', localtime ); biDeriveByDate('Table_Str',$sysdate,\@lIndx,\@lResVals) In a perl script, when I'm trying to pass $sysdate to some external function it's not working since $sysdate is passed as a string mentioned above but my function is expecting a date value... (1 Reply)
Discussion started by: Devesh5683
1 Replies

2. Shell Programming and Scripting

After exit from function it should not call other function

Below is my script that is function properly per my conditions but I am facing one problem here that is when one function fails then Iy should not check other functions but it calls the other function too So anyone can help me how could i achieve this? iNOUT i AM GIVING TO THE... (1 Reply)
Discussion started by: rohit22hamirpur
1 Replies

3. Shell Programming and Scripting

How to Call external function in .C or .So (Shared Object)

Hi, Anybody know any way to Call with Shell Script an external function wrote in .C or .So (Shared Object) on AIX enviroment and returning parameters of .C or .SO to Shell Script? Tks!! (6 Replies)
Discussion started by: rdgsantos
6 Replies

4. Infrastructure Monitoring

diffrence between method call and function call in perl

Hello, I have a problem with package and name space. require "/Mehran/DSGateEngineLib/general.pl"; use strict; sub System_Status_Main_Service_Status_Intrusion_Prevention { my %idpstatus; my @result; &General_ReadHash("/var/dsg/idp/settings",\%idpstatus); #print... (4 Replies)
Discussion started by: Zaxon
4 Replies

5. Shell Programming and Scripting

Function Call

How we can start a process if doesn't exists before? (1 Reply)
Discussion started by: Zaxon
1 Replies

6. Shell Programming and Scripting

Can you ref/link/import a function from external ksh script?

Hey guys, I'm not the best AIX scripter about but I can flounder my way thru them to create what I need. Anyhow, I have various scripts that perform various actions and processes. I was tasked to come up with a single form of logging that all the scripts could implement so that the output... (2 Replies)
Discussion started by: isawme
2 Replies

7. Shell Programming and Scripting

Calling external function in a shell

hi guys, how r u??? please I need you, help me please. I have a shell, in this shell i have this function and another code lines, this function is getting date one day back. the function is in the same shell (FILE 1) Now I need put this function in another file (FILE 2) and calling... (4 Replies)
Discussion started by: acevallo
4 Replies

8. Shell Programming and Scripting

external function in awk

Hi all, I have a basic doubt. Is there any way to use external functions (i.e. functions not defined in AWK), in AWK. I have a shell script in which I'm using a AWK snippet. In this snippet I'm calling a function defined in the shell script. But the AWK snippet is not working. I figured that... (5 Replies)
Discussion started by: kamel.seg
5 Replies

9. Shell Programming and Scripting

help on function call

hello, when i call function inside awk traitement it doesn't work, i don't have error execution but i don't get result and if i call the function outside awk traitement it work well.. there's something special in awk call function?? here is the example : awk -F "," '{ {first=$1; sec=$2;... (3 Replies)
Discussion started by: kamel.seg
3 Replies

10. Shell Programming and Scripting

Possible to call external script?

Hi Is it possible to have a bash script call an external bash script? For instance, I have a series of monitor scripts that check for running services (such as httpd, postmaster). Each monitor script is individual to the service. If a service fails, I would like to have a larger script that goes... (3 Replies)
Discussion started by: mikie
3 Replies
Login or Register to Ask a Question