how to call a function from one file to another file

Please support our Shell Scripting advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2006
Posts: 2
Reputation: selvam.cit is an unknown quantity at this point 
Solved Threads: 0
selvam.cit selvam.cit is offline Offline
Newbie Poster

how to call a function from one file to another file

 
0
  #1
Jul 25th, 2006
hi,

i am having two files

n.sh
here i wrote code like
clear
f()
{
echo "this is my program to test function"
}

again

i am having one more file

n1.sh

here i wrote like this

./home/selvam (this is my program directory (ie.. actual n.sh file is in this directory}

again i am calling the function

f -> this is function calling . this function already defined in n.sh file

but i was run this script it shows the error as

n1.sh: f : the command not found

what is solution to this problem

help to me

thanks
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: how to call a function from one file to another file

 
0
  #2
Jul 25th, 2006
if n.sh doesn't contain anything but functions and variables (i.e. no actual executed code) then add ". <path>/n.sh" to the top of n1.sh. If n.sh is a full functional script, then you cannot do this. If you have common functions that you wish to use over multiple scripts, then place these functions into their own file (preferable without a "#!" line at the top). In this way, every script that wants to use those functions can include them using the "." line presented earlier.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: how to call a function from one file to another file

 
0
  #3
Aug 2nd, 2006
Debugging code is twice as hard as writing it, so
by definition, if you code to the best of your ability,
you are not capable of debugging it.

(I don't remember who it was that said this or I would
acknowledge him.)
http://cboard.cprogramming.com/member.php?u=5094
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 2,467
Reputation: masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of masijade has much to be proud of 
Solved Threads: 267
Moderator
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Maven

Re: how to call a function from one file to another file

 
0
  #4
Aug 9th, 2006
I can't read that link (I am not a member of that site so it simply brings me to a login page).
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 5,051
Reputation: John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold John A is a splendid one to behold 
Solved Threads: 332
Team Colleague
John A's Avatar
John A John A is offline Offline
Vampirical Lurker

Re: how to call a function from one file to another file

 
0
  #5
Aug 9th, 2006
From Dave_Sinulka's signature (CBoard member):
Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
"Technological progress is like an axe in the hands of a pathological criminal."

All my posts may be freely redistributed under the terms of the MIT license.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for Shell Scripting
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC