David,
Moving the function definitions into a separate directory resolves the problem.
I was wondering if this behavior is documented anywhere?
Thanks,
Herbert.
On 06/21/2010 01:08 PM, David Korn wrote:
cc: [email protected]
Subject: Re: [ast-developers] problem with command substitution in here doc,
autoload function, and FPATH
--------
I am debugging a ksh problem reported on Linux by one of our customers, and in t
he process of trying to reduce the testcase to something more manageable I came
across some odd behavior. Different ksh versions behave differently for this ti
ny testcase (see below).
The ksh93 version shipped with Oracle and Red Hat Enterprise Linux 5 (Version AJ
M 93t+ 2010-02-02) prints too many lines of output, and reports the error "redir
ection failed" when the script tries to print more (when the test script paramet
er> 6).
The dtksh version (Version M-12/28/93d) on Solaris 5.10 omits some output.
The version on an OpenSolaris machine (Version M 93t 2008-11-04) dumps core with
out any output.
I found some old Linux ksh binaries here: http://unixlabplus.com/linux-rpm/ . T
hese appear to have a problem finding one of the scripts in $PATH, and don't pro
duce any output, just errors.
A version built from ftp://fr2.rpmfind.net/linux/ASPLinux/sources/SRPMS.12/ksh-2
0070111-1.src.rpm appears to work correctly for this testcase. It fails on the
larger customer testcase.
::::::::::::::
t1
::::::::::::::
export COUNT=${1:-1}
export FPATH=.
typeset -fu t2
cat<<EOF
$(t2 t3 echo "$COUNT" abcdefghijklmnopqrstuvwxyz )
$(t2 t3 echo "$COUNT" ABCDEFGHIJKLMNOPQRSTUVWXYZ "$(t2 t3 call 1234567890123456
7890)")
EOF
::::::::::::::
t2
::::::::::::::
function t2
{
script=${1}.sh
shift
${script} $@
}
::::::::::::::
t3.sh
::::::::::::::
case $1 in
"echo")
i=$2
shift 2
while [ ${i} -gt 0 ]
do
echo "$@ $i"
let i=i-1
done
;;
"call")
shift
echo $(t2 t3 echo $COUNT ${.sh.version} $@)
;;
esac
::::::::::::::
Correct output (I believe):
# /tmp/ksh.2007-01-11 t1 1
abcdefghijklmnopqrstuvwxyz 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ Version M 1993-12-28 s 12345678901234567890 1 1
The EL5 /bin/ksh93 output:
# /bin/ksh93 t1 1
abcdefghijklmnopqrstuvwxyz 1
abcdefghijklmnopqrstuvwxyz 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ Version AJM 93t+ 2010-02-02 12345678901234567890 1 Ve
rsion AJM 93t+ 2010-02-02 12345678901234567890 1
Version AJM 93t+ 2010-02-02 12345678901234567890 1 Version AJM 93t+ 2010-02-02 1
2345678901234567890 1 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ Version AJM 93t+ 2010-02-02 12345678901234567890 1 Ve
rsion AJM 93t+ 2010-02-02 12345678901234567890 1 Version AJM 93t+ 2010-02-02 123
45678901234567890 1 Version AJM 93t+ 2010-02-02 12345678901234567890 1 1
# /bin/ksh93 t1 10 | wc
t1[5]: t2: redirection failed
0 0 0
If I change the path to the script in t2 to ./${script}, the Linux ksh's produce
correct output. That change also makes the EL5 ksh print the correct output.
Also, when I move the t3.sh script to a different directory in $PATH, but not in
$FPATH, the script produces correct output on EL5:
# mv t3.sh /tmp
# PATH=$PATH:/tmp
# /bin/ksh93 t1 1
abcdefghijklmnopqrstuvwxyz 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ Version AJM 93t+ 2010-02-02 12345678901234567890 1 1
# /bin/ksh93 t1 10|wc
20 640 5692
Solaris output:
$ PATH=/usr/bin:/tmp
$ mv t3.sh /tmp
$ /usr/dt/bin/dtksh t1 1
abcdefghijklmnopqrstuvwxyz 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ Version M-12/28/93d 12345678901234567890 1 1
$ mv /tmp/t3.sh .
$ /usr/dt/bin/dtksh t1 1
t1[5]: t2: line 4: t3.sh: not found
t1[5]: t2: line 4: t3.sh: not found
t1[5]: t2: line 4: t3.sh: not found
$ PATH=$PATH:
$ /usr/dt/bin/dtksh t1 1
abcdefghijklmnopqrstuvwxyz 1
ABCDEFGHIJKLMNOPQRSTUVWXYZ 1
Looks like some bug in FPATH handling is causing io buffer corruption, or a file
descriptor mixup?
Thanks,
Herbert.
It looks as if you have both t2 and t3.sh in the directory name by FPATH.
Directories named by FPATH, can hold function definitions, built-in
definitions, or type definitions. Anything else is undefined.
If you put t2 in a separate directory and put this directory in FPATH,
this script should work (at least with ksh93t+).
I will add an error message to ksh93u when it detects that a file
from FPATH did not load the named target.
David Korn
[email protected]
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers