Solved

current shell funcitons

Posted on 2001-09-13
9
241 Views
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.

Thanks
Chris
0
Comment
Question by:ChirsJB
9 Comments
 
LVL 11

Expert Comment

by:griessh
Comment Utility
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 ...

======
Werner
0
 
LVL 14

Expert Comment

by:chris_calabrese
Comment Utility
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.
0
 

Author Comment

by:ChirsJB
Comment Utility
I'm using bornshell.
0
 
LVL 14

Expert Comment

by:chris_calabrese
Comment Utility
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 {
  ...
  }
syntax.

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.
0
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 38

Expert Comment

by:yuzh
Comment Utility
  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

   
   
0
 

Author Comment

by:ChirsJB
Comment Utility
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.
0
 
LVL 14

Expert Comment

by:chris_calabrese
Comment Utility
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.
0
 

Author Comment

by:ChirsJB
Comment Utility
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.  
0
 
LVL 14

Accepted Solution

by:
chris_calabrese earned 20 total points
Comment Utility
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).
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When you do backups in the Solaris Operating System, the file system must be inactive. Otherwise, the output may be inconsistent. A file system is inactive when it's unmounted or it's write-locked by the operating system. Although the fssnap utility…
In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now