Solved

current shell funcitons

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

======
Werner
0
 
LVL 14

Expert Comment

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

Author Comment

by:ChirsJB
ID: 6480499
I'm using bornshell.
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 14

Expert Comment

by:chris_calabrese
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 {
  ...
  }
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
 
LVL 38

Expert Comment

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

   
   
0
 

Author Comment

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

Expert Comment

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

Author Comment

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

Accepted Solution

by:
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).
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Introduction Regular patching is part of a system administrator's tasks. However, many patches require that the system be in single-user mode before they can be installed. A cluster patch in particular can take quite a while to apply if the machine…
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 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.:

813 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

16 Experts available now in Live!

Get 1:1 Help Now