944,011 Members | Top Members by Rank

Ad:
Jul 25th, 2006
0

how to call a function from one file to another file

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
selvam.cit is offline Offline
2 posts
since Jul 2006
Jul 25th, 2006
0

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

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.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Aug 2nd, 2006
0

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

Quote ...
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
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006
Aug 9th, 2006
0

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

I can't read that link (I am not a member of that site so it simply brings me to a login page).
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Aug 9th, 2006
0

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

From Dave_Sinulka's signature (CBoard member):
Quote ...
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
Team Colleague
Reputation Points: 2240
Solved Threads: 338
Vampirical Lurker
John A is offline Offline
5,055 posts
since Apr 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Shell Scripting Forum Timeline: Shell Script Doubt.
Next Thread in Shell Scripting Forum Timeline: just to change directories...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC