case $1 in
"one")
printit; echo ${1} | tr 'a-z' 'A-Z' # 将参数做大小写转换!
;;
"two")
printit; echo $1 | tr 'a-z' 'A-Z'
;;
"three")

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
打赢了
感觉中国现在是钱头外交
有1900退休金你就知足吧