ksh中的替换错误错误 [英] Bad substitution error in ksh
本文介绍了ksh中的替换错误错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下KornShell(ksh)脚本应检查字符串是否为回文.我正在使用ksh88
,而不是ksh93
.
The following KornShell (ksh) script should check if the string is a palindrome. I am using ksh88
, not ksh93
.
#!/bin/ksh
strtochk="naman"
ispalindrome="true"
len=${#strtochk}
i=0
j=$((${#strtochk} - 1))
halflen=$len/2
print $halflen
while ((i < $halflen))
do
if [[ ${strtochk:i:1} == ${strtochk:j:1} ]];then
(i++)
(j--)
else
ispalindrome="false"
break
fi
done
print ispalindrome
但是在以下行中我得到了严重的替换错误:if [[ ${strtochk:i:1} == ${strtochk:j:1} ]];then
But I am getting bad substitution error at the following line : if [[ ${strtochk:i:1} == ${strtochk:j:1} ]];then
有人可以让我知道我在做什么错吗?
Can someone please let me know what I am doing wrong?
推荐答案
${strtochk:i:1}
和${strtochk:j:1}
中的子字符串语法在ksh88中不可用.要么升级到ksh93,要么使用其他语言,例如awk或bash.
The substring syntax in ${strtochk:i:1}
and ${strtochk:j:1}
is not available in ksh88. Either upgrade to ksh93, or use another language like awk or bash.
这篇关于ksh中的替换错误错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文