Cannot debug simple ksh programme

后端 未结 2 993
臣服心动
臣服心动 2021-01-24 03:02

I wrote this sample KornShell (ksh) code but it is getting bad substitution error during the if clause.

while ((i < $halflen))
do
 if [[${strtochk:i:i}==${str         


        
2条回答
  •  攒了一身酷
    2021-01-24 03:21

    You are using ksh88 but the code you tried is using ksh93 feature missing for the 88 version.

    You need to replace

    if [[${strtochk:i:i}==${strtochk:j:j}]];then
    

    with these portable lines:

    if [ "$(printf "%s" "$strtochk" | cut -c $i)" =
         "$(printf "%s" "$strtochk" | cut -c $j)" ]; then
    

    and the incorrect:

    i++
    j--
    

    with:

    i=$((i+1))
    j=$((j-1))
    

提交回复
热议问题