views:

332

answers:

4

I have uncovered another problem in the effort that we are making to port several hundreds of ksh scripts from AIX, Solaris and HPUX to Linux. See here for the previous problem.

This code:

#!/bin/ksh
if [ -a k* ]; then
    echo "Oh yeah!"
else
    echo "No way!"
fi
exit 0

(when run in a directory with several files whose name starts with k) produces "Oh yeah!" when called with the AT&T ksh variants (ksh88 and ksh93). On the other hand it produces and error message followed by "No way!" on the other ksh variants (pdksh, MKS ksh and bash).

Again, my question are:

  • Is there an environment variable that will cause pdksh to behave like ksh93? Failing that:
  • Is there an option on pdksh to get the required behavior?
A: 

You do realize that [ is an alias (often a link, symbolic or hard) for /usr/bin/test, right? So perhaps the actual problem is different versions of /usr/bin/test ?

OTOH, ksh overrides it with a builtin. Maybe there's a way to get it to not do that? or maybe you can explicitly alias [ to /usr/bin/test, if /usr/bin/test on all platforms is compatible?

pjz
[ is a builtin command in both ksh93 and pdksh..
Andrew Stein
+3  A: 
Cyberdrow
A: 

Well after one year there seems to be no solution to my problem.

I am adding this answer to say that I will have to live with it......

Andrew Stein
A: 

in Bash the test -a operation is for a single file.

I'm guessing that in Ksh88 the test -a operation is for a single file, but doesn't complain because the other test words are an unspecified condition to the -a.

you want something like

for K in /etc/rc2.d/K* ; do test -a $K && echo heck-yea ; done

I can say that ksh93 works just like bash in this regard. Regrettably I think the code was written poorly, my opinion, and likely a bad opinion since the root cause of the problem is the ksh88 built-in test allowing for sloppy code.

masta