b2科目四模拟试题多少题驾考考爆了怎么补救
b2科目四模拟试题多少题 驾考考爆了怎么补救

shell脚本for循环 鸟哥的linux私房菜(7)

电脑杂谈  发布时间:2018-01-07 20:06:31  来源:网络整理

case $1 in

"one")

printit; echo ${1} | tr 'a-z' 'A-Z' # 将参数做大小写转换!

;;

"two")

printit; echo $1 | tr 'a-z' 'A-Z'

;;

"three")

shell脚本for循环_shell脚本for循环数组_shell脚本for循环100次

printit; echo $1 | tr 'a-z' 'A-Z'

;;

*)

echo "Usage $0 {one|two|three}"

;;

esac

---------

以上面的例子来说,鸟哥做了一个函数名称为 printit ,所以,当我在后续的程序段里面, 只要执行printit 的话,就表示我的 shell script 要去执行『 function printit .... 』 里面的那几个程序段落

13.5 循环(loop)

13.5.1 while do done ,until do done(不定循环)

语法

当 condition 条件成立时,就进行循环,直到condition 的条件不成立才停止:

while [ condition ]

do

程序段落

done

与 while 相反,它说的是『当 condition 条件成立时,就终止循环, 否则就持续进行循环的程序段。

until [ condition ] ]

do

程序段落

done

范例

[dmtsai@study bin]$ vim yes_to_stop.sh

#!/bin/bash

# Program:

# Repeat question until user input correct answer.

# History:

# 2015/07/17 VBird First release

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin

export PATH

while [ "${yn}" != "yes" -a "${yn}" != "YES" ]

do

read -p "Please input yes/YES to stop this program: " yn

done

echo "OK! you input the correct answer."

[dmtsai@study bin]$ vim yes_to_stop- - 2.sh

#!/bin/bash

# Program:

# Repeat question until user input correct answer.

# History:

# 2015/07/17 VBird First release

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin

export PATH

until [ "${yn}" == "yes" -o "${yn}" == "YES" ]

do

read -p "Please input yes/YES to stop this program: " yn

done

echo "OK! you input the correct answer."


本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/jisuanjixue/article-58905-7.html

相关阅读
    发表评论  请自觉遵守互联网相关的政策法规,严禁发布、暴力、反动的言论

    热点图片
    拼命载入中...