1842543 Members
2208 Online
110189 Solutions
New Discussion

ksh ENV variable

 
Johan Bergström
Occasional Advisor

ksh ENV variable

Hello.

Can I somehow source more than one file in the ENV variable in ksh ?

Usually it's set to $HOME/.kshrc but I'd like to source for example a global /etc/kshrc AND then $HOME/.kshrc

The problem is that I have several users spread over several machines and they all have their own .kshrc. Now I want to add some aliases to their shell, but I don't want to edit every users $HOME/.kshrc

If I set the aliases in /etc/profile they are there as they should in the login shell, but if I change shell, or run a script, they won't be in the new shell that's executed, that's why I think I need to set them in a global kshrc aswell.
7 REPLIES 7
Dennis Handly
Acclaimed Contributor

Re: ksh ENV variable

>Can I somehow source more than one file in the ENV variable in ksh?

No. The best you can do is source a new file then source /etc/kshrc AND then $HOME/.kshrc.

Anyway, why do you have any control over ENV? I reset it in my .profile, why would you expect your users to do anything different?

>that's why I think I need to set them in a global kshrc as well.

That's correct. But if you are offering a service with these aliases, your users should be glad to change their .kshrc files and source your new file.

Of course if these aliases are part of a management stick, I can see why they wouldn't. ;-)
Rasheed Tamton
Honored Contributor

Re: ksh ENV variable

Hello,

Did you check the global function feature of ksh. May be it can be an option for you in this case.
Peter Nikitka
Honored Contributor

Re: ksh ENV variable

Hi,

it depends on the way, where $ENV is set:
If you do that in /etc/profile, you have won:
Modify the setting to:
ENV=/usr/local/etc/ksh.aliases
export ENV

and at the end of /usr/local/etc/ksh.aliases
add something like:

if alias setglobalaliases 2>/dev/null
then :
elif [ -s ~/.kshrc ]
then . ~/.kshrc
fi

When the above condition is not met, you'll have to do it the other way round:
Add an anchor - similar to the above solution - to every .kshrc (you have to change this for every existing user only once):

if alias setglobalaliases 2>/dev/null
then :
elif [ -s /usr/local/etc/ksh.aliases ]
then . /usr/local/etc/ksh.aliases
fi


In both cases, add into your global aliases-file the anchor-alias and your other stuff:
cat /usr/local/etc/ksh.aliases
alias setglobalaliases=true
alias lspr='lpstat -o$PRINTER'
...


mfG Peter
The Universe is a pretty big place, it's bigger than anything anyone has ever dreamed of before. So if it's just us, seems like an awful waste of space, right? Jodie Foster in "Contact"
Dennis Handly
Acclaimed Contributor

Re: ksh ENV variable

Actually ENV should be this complicated string and then you set FILE or some other variable to your actual file:
export ENV='${FILE[(_$-=1)+(_=0)-(_$-!=_${-%%*i*})]}'

This doesn't set aliases for scripts, only interactive shells.
Johan Bergström
Occasional Advisor

Re: ksh ENV variable

Dennis, that only checks if the shell is interactive or not.

Anyway, I solved my problem without using aliases at all, fiddeling with the PATH variable instead.

Thanks for your help tho.
Johan Bergström
Occasional Advisor

Re: ksh ENV variable

Solved the problem elsewhere, didn't use aliases or the ENV variable at all.
Dennis Handly
Acclaimed Contributor

Re: ksh ENV variable

>That only checks if the shell is interactive or not.

Exactly, if you aren't interactive, you shouldn't be using aliases, etc. It makes your scripts/subshells start faster.