1745814 Members
3824 Online
108722 Solutions
New Discussion юеВ

ksh bug?

 
MoreSawdust
Advisor

ksh bug?

I have a ksh script issue where it appears that /usr/bin/ksh ignores an alias, and searches for it elsewhere (namely FPATH).

The script in question makes use of some aliases that are created by a dotted in script. These are aliases used by dozens of Oracle-related scripts, and they work elsewhere, all the time (or we would be down hard!).

I've put "alias | grep " before and after the alias reference, and it displays the alias accurately, but in execution it can't find it (and sets ${?} to 1). Stderr shows that that the alias was not found.

If I replace the alias call with the actual script name, it works just fine. But - I don't want to do that because it defeats the purpose of the aliases - which is to enable us to alter Oracle environments using one script.

The script also calls some functions that are accessed via "typeset -fu ...." and "typeset FPATH="...". When I create a function with the same name as the alias, it finds it, and executes it as a function.

PHCO-38559 is installed.

Is this a bug? What's the expected behavior? I can't find a definitive reference as to the search order for aliases, functions, etc.
The people are the hardest part.
3 REPLIES 3
James R. Ferguson
Acclaimed Contributor

Re: ksh bug?

Hi:

Did the script in question suddenly stop working on the server on which you have the problem or is this the first time running it there?

A sample of code that demonstrates the problem would be very nice to see.

That said, the search order should be:

1. keywords
2. aliases
3. shell builtins
4. functions
5. external programs found via the PATH variable

Regards!

...JRF...
Dennis Handly
Acclaimed Contributor

Re: ksh bug?

>I've put "alias | grep " before and after the alias reference,

Have you tried "whence -v "?

If you quote the first char of an alias, it isn't one.
Laurent Menase
Honored Contributor

Re: ksh bug?

how do you execute your script?
It just means that your default definition file was not sourced ( . file )

where are the alias defined? in what file?
.profile? .kshrc?
does the .profile defined the ENV variable?
Depending on how you exectute your script those files are not sourced,
- to check that you can at a echo in your .profile/.kshrc, to see if they are sourced.
then if you need them you can either:
explicitely source them in your script for instance.
. /somewhere/mydefaultdefinitions

or test if a variable is defined before sourcing
if [ -z "${MYVARIABLE}" ]
then
. /somewhere/mydefaultdefinitions
fi