SLES 12 syntax error: '=~' unexpected operator/operand

SLES 12 syntax error: '=~' unexpected operator/operand

我已经为 SLES11 开发了一个更大的脚本,一切正常 运行。 但是对于 SLES12,启动脚本时会出现一些语法错误。

错误:syntax error: '=~' unexpected operator/operand

#!/bin/ksh

while [[ ! $BIGTAB =~ ^-?[0-9* ]+$ ]] || [[ ! $BIGTAB -ge 1 ]]; do
echo "  Enter number of tables to display:"
read BIGTAB
...

=~好像不支持了!? 你能给我帮助吗,如何替换 SLES12 的语法(以及 SLES11 下的 运行)。

谢谢!

我没有 SLES12 来测试它,但你的问题似乎不是 =~ 运算符,而是你的操作数(正则表达式中间有一个 space) .

试试这个:

[[ ! $BIGTAB =~ ^-?[0-9]+$ ]]

您正在 SLES 12 上使用 legacy ksh(基于 mksh):

# echo $KSH_VERSION
@(#)LEGACY KSH R54 2016/11/11
# [[ a =~ a ]]
ksh: syntax error: '=~' unexpected operator/operand
#

因此您需要安装 real ksh/ksh93(虽然不确定 SLES 上的 pkg 名称是什么)。

# echo $KSH_VERSION
Version AJM 93u+ 2012-08-01
# [[ a =~ a ]]
#

更新:

刚刚查看了 SUSE 的网站,SLES 11 but only mksh in SLES 12 中有 ksh(没有 mksh)。

更新#2:

根据SLES 12 SP1release notes, you need to install the legacy module找回ksh。

1.4.1.3 Support for Korn Shell (ksh) Extended Until End of March 2022

Support for the legacy package ksh in SLE was originally slated to end in 2017. However, many customers still depend on ksh.

Support for ksh has been extended until the end of March 2022.

Beyond that time, you can use the mksh implementation of Korn Shell (package mksh). However, as mksh is based on pdksh, there are certain functional differences. For example, its handling of pipelines is similar to Bash.

8.2.5 KSH 93v Replaced with KSH 93u Report

In the Legacy Module for SUSE Linux Enterprise 12, we shipped KSH 93v. However, the 93v branch was not fully stable yet.

With SLE 12 SP1, we release KSH 93u, which is more stable version 93v. In order to provide a regular update path from 93v to 93u, a higher version number (93vu) has been used for this update.