Solved

current shell funcitons

Posted on 2001-09-13
9
242 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to check for shares on aix 1 65
Linux : can't create transaction lock on rpm.lock (Permission denied) 10 136
Can I delete authorized_keys in FreeBSD 1 76
Image not there 4 44
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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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 get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…

919 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

20 Experts available now in Live!

Get 1:1 Help Now