Shell语法 条件、循环

来源:互联网 发布:淘宝哪家电脑主机好 编辑:程序博客网 时间:2024/06/05 15:17
if [ expression 1 ]then   Statement(s) to be executed if expression 1 is trueelif [ expression 2 ]then   Statement(s) to be executed if expression 2 is trueelif [ expression 3 ]then   Statement(s) to be executed if expression 3 is trueelse   Statement(s) to be executed if no expression is truefi
casein模式1【支持正则】)    command1    command2    command3    ;;模式2【支持正则】)    command1    command2    command3    ;;*)    command1    command2    command3    ;;esac
for 变量 in 列表do    command1    command2    ...    commandNdone例for loop in 1 2 3 4 5do    echo "The value is: $loop"done
while循环COUNTER=0while [ $COUNTER -lt 5 ]do    COUNTER='expr $COUNTER+1'    echo $COUNTERdone##依次将文件的每一行赋给变量#!/bin/bashwhile read iid;do        echo "[$iid]"done <./iid
跳出循环break命令continue命令
1 0
原创粉丝点击