How to Overcome an Incompatibility Between the Ksh on Linux VS. That Installed on Aix/Solaris/Hpux

How to overcome an incompatibility between the ksh on Linux vs. that installed on AIX/Solaris/HPUX?

After some advice from people in my company we decided to make the following modification to the code. This gives us the same result whether using the "real" ksh's (ksh88, ksh93) or any of the ksh clones (pdksh, MSK ksh). This also works correctly with bash.

#!/bin/ksh
echo "a\nb" > junk
flag=false
while read x
do
flag=true
done < junk
echo "flag = ${flag}"
exit 0

Thanks to jj33 for the previous accepted answer.

REDUX: How to overcome an incompatibility between the ksh on Linux vs. that installed on AIX/Solaris/HPUX?

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......

process substitution not working in ksh on AIX

You can try this:

lsvgfs `lsvg | grep -v rootvg` | while read -r line; do
var1=$(...)
var2=$(...)
echo "$var1 $var2"
done

assignation variable under different ksh environment

Short answer: use ksh93 on all platforms.

The set -A syntax to assign values to an works in all versions of ksh. You only need to use the alternate typeset -a syntax if you run your script under bash. The easiest solution would be to always run your code under ksh. All your platforms have ksh93, so just use that: on Linux, install the ksh package and use it instead of bash. Under ksh93, you can also use a=(aModeTrace false false false false); this also works in bash but not in ksh88 (AIX's ksh is ksh88 but there is also aksh93`).

If you absolutely need a script that's portable between ksh88 and bash, you can put the eval hackery in functions. Only whole array assignment needs to be wrapped in this way, the syntax for access to individual elements, array size and individual element assignment is the same. Use the shell, rather than the operating system, to choose the implementation.

## set_array ARRAY ELEMENT0 ELEMENT1 …
## Set the variable ARRAY to contain the specified elements. Like
## ARRAY=(ELEMENT0 ELEMENT1 …), but also supply a method that works in ksh88.
if [[ -n $BASH_VERSION ]]; then eval '
set_array () { eval "shift; $1=(\"\$@\")"; }'
else eval '
set_array () { typeset __set_array_var=$1; shift
set -A $__set_array_var -- "$@"
}'
fi

(Note that in ksh, set -A "$@" almost works, but not quite: it fails if the first element of the array begins with a dash.)

String assignments and quoting work in the same way in all shells, there is no portability issue there.

To assign the output of a command, use command substitution (again, it's portable). The only way the output is changed is that trailing newlines are removed (unlike read which expands backslashes and trims leading and trailing whitespace).

Result="$(printf '%s%s' "${ThisLine}" "${cst_PrintfPipeOS}" | 
sed -e "s/^\(.\{${SampleSize}\}\).*/\1/")"

ksh: cannot execute a compiled c library

I will be compiling the source files,
as Linux 64-bit binary is for the x86_64/amd64 architecture, while there's a significant chance that AIX system might be a POWER architecture .



Related Topics



Leave a reply



Submit