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 a
ksh93`).
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
Arm Linux Atags VS Device Tree
How Does Stat Command Calculate the Blocks of a File
Udev - Run Program on Usb Flash Drive Insert
How to Calculate the Total Size of Certain Files Only, Recursive, in Linux
Interrupting Epoll_Wait with a Non-Io Event, No Signals
Using a User's .Bashrc in a Systemd Service
Remove ^H and ^M Characters from a File Using Linux Shell Scripting
What Does "< /Dev/Null >& /Dev/Null" at the End of a Command Do
How to Load a Specific Version of R in Linux
What Is the Best Tool to Convert Common Video Formats to Flv on a Linux Cli
Error: Ld.So: Object 'Libgtk3-Nocsd.So.0' from Ld_Preload Cannot Be Preloaded
Shell Script Change Directory with Variable
Run Docker in Ubuntu Live Disk
How to "Git Pull" - Host Key Verification Failed
Linux X86-64 Assembly and Printf
Cannot Clone Repository: Fatal: R Any Gitolite-Admin Gitolite Denied by Fallthru