Iterating through a range of ints in ksh?

后端 未结 7 391
故里飘歌
故里飘歌 2020-12-30 22:51

How can I iterate through a simple range of ints using a for loop in ksh?

For example, my script currently does this...

for i in 1 2 3 4 5 6 7
do
            


        
相关标签:
7条回答
  • 2020-12-30 23:35

    The following will work on AIX / Linux / Solaris ksh.

    #!/bin/ksh
    
    d=100
    
    while (( $d < 200 ))
    do
       echo "hdisk$d"
      (( d=$d+1 ))
    done
    

    Optionally if you wanted to pad to 5 places, i.e. 00100 .. 00199 you could begin with:

    #!/bin/ksh
    typeset -Z5 d
    

    -Scott

    0 讨论(0)
提交回复
热议问题