![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| help on function call | kamel.seg | Shell Programming and Scripting | 3 | 01-08-2008 04:16 AM |
| function call | kamel.seg | Shell Programming and Scripting | 2 | 12-28-2007 11:58 AM |
| call function | Jamil Qadir | Shell Programming and Scripting | 4 | 03-20-2007 02:07 AM |
| Help with a function call | Stevhp | High Level Programming | 6 | 03-04-2007 11:44 PM |
| function call | forever_49ers | Shell Programming and Scripting | 3 | 09-13-2006 03:26 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to Call a Function with in two files
Hi all,
I am having a problem with my code I am having a file from which i am calling a function, which is present in another file, for this i am using . <file name> followed by the function name, when i am doing like this, second file completely it is executing... example File1 Code: . file2.ksh tmp=1 fn_test $tmp File2 Code: fn_test() { echo $tmp } echo test here the output will be 1 test where i want only the value present in that function, i don;t want the code present outside of that function to execute how to call only the particular function present in the file 2 thanks in advance |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
afaik, when using ksh, you may not call only a function which is present in another file. you may execute another file (execute it completely)
use Perl, Python, TCL to do what you are trying |
|
#3
|
|||
|
|||
|
Code:
. file2.ksh > /dev/null tmp=1 fn_test $tmp |
|
#4
|
||||
|
||||
|
Quote:
Jean-Pierre. |
|
#5
|
||||
|
||||
|
Quote:
Something like Code:
fn_test()
{
echo $tmp
}
fn_echo ()
{
echo test
}
|
|
#6
|
|||
|
|||
|
Vino has it. Create an "include" file. Source the file which has just functions.
So if you have 3 files: file1.sh file2.sh and myfunctions.sh: The first executable line in file1.sh is: Code:
. /path/to/myfunctions.sh Code:
. /path/to/myfunctions.sh |
|
#7
|
|||
|
|||
|
hsekol
Hi all,
Thanks for your reply, I tried the following code and it is working for me . file2.ksh > /dev/null but aigles has posted that "Doesn't suppress execution of commands outside function definitions, this can be very dangerous." can any body explain in what way it is dangerous for me to use this method Actually my requirement is i have a file, which i need to run the both from command line and also from any file, for which i have created one main script and i have written some code outside of the function and calling the main function to execute from command line can i proceed using the above code are is there any approach or procees to acheive it, if so please reply me Thanks in advance |
|||
| Google The UNIX and Linux Forums |