Unix Shell - Loop statement

来源:互联网 发布:网络球型监控摄像头 编辑:程序博客网 时间:2024/04/30 13:39

 #!/bin/ksh


######### FOR #################

for i in HUP INT QUIT TERM
do
  echo $i
done


#cat f.txt
#aa ab
#ba bb bc
#
#!/bin/ksh

for word in `cat f.txt`
do
    echo $word
done

######### WHILE #################


BEGIN=1
END=10
IDX=$BEGIN

while [ $IDX -ge $BEGIN -a $IDX -le $END ]
do
    echo $IDX
    IDX=$((IDX + 1))
done


while $expr
do
...
done


while (true)
do
   ...
done

 
while read i X
do
    echo $i $X
done < f.txt


ls -1s *.out | sort | while read X table_file
do
    ...
done


# Execute all the ttSize() built-in procedures
$X10_BIN/ttIsql -connStr dsn=tt41data <<-EOF | grep "^< " | cut -d' ' -f2 | cut -d'.' -f1 | while read SIZE
    $SQL
    exit
EOF
do
    # Add the size of each table to totSize
    ((totSize = totSize + SIZE))
done

 

continue     #continue next for variable
break            #break from loop

原创粉丝点击