如何克服Linux上的ksh与AIX/Solaris/HPUX上安装的ksh之间的不兼容? [英] How to overcome an incompatibility between the ksh on Linux vs. that installed on AIX/Solaris/HPUX?

查看:283
本文介绍了如何克服Linux上的ksh与AIX/Solaris/HPUX上安装的ksh之间的不兼容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参与了将包含数百个ksh脚本的系统从AIX,Solaris和HPUX移植到Linux的过程.我在ksh在两个系统上的行为方式上遇到了以下差异:

I am involved in the process of porting a system containing several hundreds of ksh scripts from AIX, Solaris and HPUX to Linux. I have come across the following difference in the way ksh behaves on the two systems:

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

在AIX,Solaris和HPUX上,输出为"flag = true";在Linux上,输出为"flag = false".

On AIX, Solaris and HPUX the output is "flag = true" on Linux the output is "flag = false".

我的问题是:

  • 是否有一个环境变量,可以将其设置为使Linux的ksh像 其他Os的?失败:
  • Linux的ksh上是否有一个选项可以获取所需的行为?失败:
  • 是否有可用于Linux且具有所需行为的ksh实现?
  • Is there an environment variable that I can set to get Linux's ksh to behave like the other Os's'? Failing that:
  • Is there an option on Linux's ksh to get the required behavior? Failing that:
  • Is there a ksh implementation available for Linux with the desired behavior?

其他说明:

  • 在AIX上,Solaris和HPUX ksh是ksh88的变体.
  • 在Linux上,ksh是公共域ksh(pdksh)
  • 在AIX上,Solaris和HPUX dtksh和ksh93(在其中安装了它们)与ksh一致
  • 我可以访问的Windows NT系统:Cygwin和MKS NT与Linux一致.
  • 在AIX,Solaris和Linux上,bash一致,给出错误的结果(从我看来)为"flag = false".

下表总结了系统存在的问题:

The following table summarizes the systems the problem:

uname -s       uname -r                   which ksh          ksh version                     flag =
========       ========                   =========          ===========                     ======
Linux          2.6.9-55.0.0.0.2.ELsmp     /bin/ksh           PD KSH v5.2.14 99/07/13.2       false
AIX            3                          /bin/ksh           Version M-11/16/88f             true    // AIX 5.3
                                          /bin/ksh93         Version M-12/28/93e             true
SunOS          5.8, 5.9 and 5.10          /bin/ksh           Version M-11/16/88i             true
                                          /usr/dt/bin/dtksh  Version M-12/28/93d             true
HP-UX          B.11.11 and B.11.23        /bin/ksh           Version 11/16/88                true
                                          /usr/dt/bin/dtksh  Version M-12/28/93d             true
CYGWIN_NT-5.1  1.5.25(0.156/4/2)          /bin/ksh           PD KSH v5.2.14 99/07/13.2       false
Windows_NT     5                          .../mksnt/ksh.exe  Version 8.7.0 build 1859...     false    // MKS

更新

在我公司的一些人员提出建议之后,我们决定对代码进行以下修改.无论使用真实的" ksh(ksh88,ksh93)还是任何ksh克隆(pdksh,MSK ksh),这都给我们相同的结果.这对于bash也可以正常使用.

Update

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

感谢jj33先前接受的答案.

Thanks to jj33 for the previously accepted answer.

推荐答案

在我公司的一些建议之后,我们决定对代码进行以下修改.无论使用真实的" ksh(ksh88,ksh93)还是任何ksh克隆(pdksh,MSK ksh),这都给我们相同的结果.这对于bash也可以正常使用.

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

感谢jj33提供了先前接受的答案.

Thanks to jj33 for the previous accepted answer.

这篇关于如何克服Linux上的ksh与AIX/Solaris/HPUX上安装的ksh之间的不兼容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆