Solved

current shell funcitons

Posted on 2001-09-13
9
246 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
[X]
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
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
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
FreeBSD on EC2 FreeBSD (https://www.freebsd.org) is a robust Unix-like operating system that has been around for many years. FreeBSD is available on Amazon EC2 through Amazon Machine Images (AMIs) provided by FreeBSD developer and security office…
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…
In a previous video, we went over how to export a DynamoDB table into Amazon S3.  In this video, we show how to load the export from S3 into a DynamoDB table.

705 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