Operating System - Linux
1827720 Members
3207 Online
109968 Solutions
New Discussion

Re: function defined in /etc/profile

 
Tammy Liang
Regular Advisor

function defined in /etc/profile

I have functions defined in /etc/profile, but
did not display as environment variable.
How can I set up function as environment variable on hp-ux 11.11?
take easy, enjoy life
12 REPLIES 12
OldSchool
Honored Contributor

Re: function defined in /etc/profile

Could you post a sample of what you're doing (for clarity)?
James R. Ferguson
Acclaimed Contributor

Re: function defined in /etc/profile

Hi Tammy:

In the profile, do something like this:

...
function IAM {
echo "I'm ok..."
}
export IAM
...

..Now when you login, at the command prompt you can type:

$ IAM
I'm ok...

...and you can see:

$ typeset
$ typeset|grep IAM
export IAM

Regards!

...JRF...
Tammy Liang
Regular Advisor

Re: function defined in /etc/profile

I have function cvs defined in /etc/profile.
When I run env | grep -i cvs, I don't see the cvs function. I setup a linux redhat system, and also defined function cvs in /etc/profile. I can see this cvs function when I run env |grep -i cvs on redhat es4 system.
How can I setup function as global environment variable, so I can see via env command?

function cvs
{
USER=`id -un`
if [ "$USER" = "appmgr" ] || [ "$USER" = "oracle" ] || [ "$USER" = "root" ]
then
/usr/bin/cvs -d :pserver:cvsread@$CVSROOT $@
else
/usr/bin/cvs -d :pserver:$USER@$CVSROOT $@
fi
}

$ env | grep -i cvs
CVS_RSH=remsh
CVSROOT=akrengcvs1:/cvs


$ env | grep -i cvs
CVSROOT=akrengcvs1:/cvs
cvs=() { if [ "$USER" = "appmgr" ] || [ "$USER" = "oracle" ] || [ "$USER" = "root" ]; then
/usr/bin/cvs -d :pserver:cvsread:cvsread@$CVSROOT $@;
/usr/bin/cvs -d :pserver:$USER@$CVSROOT $@;

take easy, enjoy life
spex
Honored Contributor

Re: function defined in /etc/profile

Hi Tammy,

# typeset -f | grep cvs

PCS
Tammy Liang
Regular Advisor

Re: function defined in /etc/profile

$ typeset -f |grep -i cvs
function cvs
/usr/bin/cvs -d :pserver:cvsread@$CVSROOT $@
/usr/bin/cvs -d :pserver:$USER@$CVSROOT $@
take easy, enjoy life
spex
Honored Contributor

Re: function defined in /etc/profile

Tammy,

If you want the entire body of function cvs returned:

# typeset -f | awk '/^function cvs$/,/^\}$/ {print}'

PCS
Tammy Liang
Regular Advisor

Re: function defined in /etc/profile

Mainly I want to be able to use cvs function that defined in /etc/profile instead of
/usr/bin/cvs. Somehow, it does not use cvs function, but use /usr/bin/cvs. How can I use cvs function, instead of /usr/bin/cvs.

Thanks for all the reply...
take easy, enjoy life
OldSchool
Honored Contributor

Re: function defined in /etc/profile

ok,

in the std /usr/bin/sh, you wont see cvs when you run "env". Use "typeset -f cvs" and it will display the contents of function cvs.

remember to "export cvs" after defining it.

Dennis Handly
Acclaimed Contributor

Re: function defined in /etc/profile

>System Administrator: remember to "export cvs" after defining it.

Hmm, I have never figured out what use exported functions can be. They are not available in other scripts like exported variables. It seems you can only do this if you use typeset -xf cvs. (export doesn't work for me.)
And you can't have #!/bin/ksh at the start of the script.
Bill Hassell
Honored Contributor

Re: function defined in /etc/profile

A more portable solution might be to create a function directory, store the function as a file in this directory and then have /etc/profile export FPATH=/functiondirectory. Now the environment will have a function path available to any script.


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: function defined in /etc/profile

>Bill Hassell: A more portable solution ...

Exactly, though the ksh/sh man pages (under Functions) say you should put them in your ENV file. This is a more individual, rather than system wide. And may only work for interactive shells if you use the magic ENV encantation.
Tammy Liang
Regular Advisor

Re: function defined in /etc/profile

Thanks for all the suggestion. I work around to write a customer script for using cvs command and ask user to use this customer cvs script. One thing I found out through this instance is that hp-ux and redhat linux threat functions that defined in /etc/profile differently.
take easy, enjoy life