精品--
如下示例:
#!/bin/bash
echo “is it morning? Please answer yes or no”
read timeofday
if [ $timeofday = “yes” ] ;then
echo “good morning”
elif [ $timeofday = “no” ]
then
echo “Good afternoon”
else
echo “sorry ,$timeofday not recognized. Enter yes or no”
exit 1
fi
exit 0
3、 一个与变量有关的问题。
如上程序,如果没有输入 Yes 和 no 直接按回车键,会出现什么结
果呢?程序会有出错信息。原因是。。。避免该问题产生的方法对
变量使用双引号“$Str”
4、 for 语句
使用 for 语句可以循环处理一组值,这组值可以是任意字符串的
集合。 它的语法形式如下:
for variable in values
--精品