ksh scripting, For loop

依然范特西╮ 提交于 2019-12-06 01:54:27

问题


#!/bin/ksh
#########################     
for i in {1..30} ;do
  echo $i
done

output is:

{1..30}  

What is wrong in my code?


回答1:


{1..30} belongs to bash.

Use this:

for((i=1;i<=30;i++)); do
    echo $i
done



回答2:


Alternatively you can switch to a while construction:

i=1
while (( i <= 30 ))
do
   echo $i
   (( i+=1 ))
done



回答3:


 for {set x 0} {$x<10} {incr x} {
             puts "x is $x"
           }


来源:https://stackoverflow.com/questions/9977485/ksh-scripting-for-loop

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!