#!/bin/shnum1=10num2=20# if then fiif [ ${num1} -gt ${num2} ]thenecho "大于"fi# if then ... else ... fiif [ ${num1} -gt ${num2} ]thenecho "大于"elseecho "小于或等于"fi# if then ... elif then ... else ... fiif [ ${num1} -gt ${num2} ]thenecho "大于"elif [ ${num1} == ${num2} ]thenecho "等于"elseecho "小于"fi# for in 循环,语法:for 变量名 in 元素1 元素2 ~ 元素n do ... donefor name in "iOSZhang" "testLiu" "JavaYang"doecho ${name}done# 或for name in iOSZhang\`s an iOS developerdoecho ${name}done# 或从变量列表里读取names=("iOSZhang" "testLiu" "JavaYang")for name in ${names}doecho ${name}done# 或目录文件读取filePath="/Users/zhangshaoyu/Desktop/MinePods/OSChina/LearnShell/code/*"for file in ${filePath}doecho $filedone# for嵌套循环,语法:for (i = 0; i < n; i++) do ... donenames=("iOSZhang" "testLiu" "JavaYang")for (( i = 0; i < 3; i++ ))dovalue=${names[i]}echo ${value}done# while循环i=0while (( i < ${#names[@]} ))dovalue=${names[i]}echo ${value}let 'i++'done# case语句age=1case ${age} in1)echo "== 1";;2)echo "== 2";;3)echo "== 3";;esac# break退出循环for (( i = 0; i < 10; i++ ))doif [[ $i -eq 5 ]]thenbreakfiecho $idone# contiune退出当前循环for (( i = 0; i < 10; i++ ))doif [ $i -eq 5 ]thencontinuefiecho $idone
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。