Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Assume I have a function.ksh file that contains a function called getServerIp. I don't want to create a new script file and import function.ksh, I just want to run getServerIp from my current shell. As far as I know this is not possible; is there some way I've missed?

share|improve this question

It's quite possible.

Create a directory (let's say $HOME/functions), and put your getServerIp function in a file called getServerIp in that directory. Make sure that file is executable.

Then all you need is to add $HOME/functions to your $FPATH environment variable and you're done - you can call getServerIp as if it was a built-in.

There are other options too. Please check out: Korn Shell Functions.

share|improve this answer
Well it is not quite what I want to do. Let s say there are several function like getServerIp, getVirtualIp, IsCluster etc. . The thing is they are all generic functions and they can be called when I import function.ksh file on another script file. What I want is just run IsCluster in command prompt. In the way you said, I should do the same settings for all functions in function.ksh. Please correct me if I am wrong. Thank you. – mibzer Oct 4 '11 at 14:51
With what I wrote above, you don't need to import anything. All the functions you place in FPATH (in files with the same name as the function) get auto-imported in your shell. You can use them directly on the command line or in scripts without any other work. – Mat Oct 4 '11 at 15:18
Yes you are we dont need to import anything. However I don t want to add my function to a new file and add it to FPATH. I need a way to call my function a way like calling a method. For example is it possible to call the function as "function.ksh getSeverIp" . I hope it is not complicated and I hope I explained myself. Thank you for your answers. – mibzer Oct 4 '11 at 19:39
create symbolic link in yout FPATH folder to the file taht contain the function having the specific wanted function as name – NeronLeVelu Mar 7 '14 at 15:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.