current shell funcitons

Posted on 2001-09-13
Last Modified: 2013-12-06
I have a program called persfuncs that contains a few simple functions.  I added it to my .profile using ". persfuncs" but the functions are not in my curent shell.  If I run it at the command line it will be available.  How do I get these functions into my current shell?  Oh, one more thing, I tried to add the functions directly into my .profile and it still did not work.

Question by:ChirsJB
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 11

Expert Comment

ID: 6479853
I guess you are using ksh, true?

The .profile is used for variables etc and sourced when you login.
For interactive execution (like opening a new xterm) it expands the ENV variable (usually soemthing like .env, .kshrc) and executes it. That's where you put your interactive functions in ...

LVL 14

Expert Comment

ID: 6480458
Another option is to create a directory to hold your functions, put it in your FPATH (like PATH, but for functions), and put the definition of each function in a file in that directory that has the same name as the function.

Author Comment

ID: 6480499
I'm using bornshell.
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 14

Expert Comment

ID: 6480550
Bourne Shell has no functions.  I'll assume you mean POSIX J shell or System V shell, both of which are derivatives of Steve Bourne's original shell that were shipped with commercial Unix systems as /bin/sh.

POSIX J shell works the same as ksh, but only if you use the
  function name {

System V shell has functions, but only the
   name() {
type, which don't work with FPATH, and this shell doesn't have
ENV either, so there's no way of doing this in System V shell.

If your system isn't running POSIX J shell as /bin/sh, then
you'll need to use a more modern shell like ksh or bash.
LVL 38

Expert Comment

ID: 6481337
  You can put the functions in your .profile. or if you are using ksh, put them in the .kshrc file, and add the followings to your .profile:
   export ENV=$HOME/.kshrc


Author Comment

ID: 6482226
If bourne shell does not have functions then why is it that if I enter funciton_name () { .....;} it works.  And if i put it into a script and execute it in the current shell it works....but not in the profile? I'm lost on this one.
LVL 14

Expert Comment

ID: 6482381
Because you're not using Steve Bourne's Bourne Shell from Bell Labs.
You're using System V Shell, which added the syntax you describe.
This is shipped as /bin/sh on Solaris and (I think) IRIX.
HP-UX ships POSIX J Shell as /bin/sh, and AIX ships KornShell
as /bin/sh.

Author Comment

ID: 6482654
I'm am using Solaris, so that explains it.  Now back to how do I get it to execute in my .profile in order to use it in my current shell.  
LVL 14

Accepted Solution

chris_calabrese earned 20 total points
ID: 6482678
You don't.  You can't do that in Solaris /bin/sh.  Use ksh or /usr/xpg4/bin/sh (which is actually a symbolic link to ksh).

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Let's say you need to move the data of a file system from one partition to another. This generally involves dismounting the file system, backing it up to tapes, and restoring it to a new partition. You may also copy the file system from one place to…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question