Chinaunix
标题:
shell脚本下的for,while,until循环运用
[打印本页]
作者:
jack_zyk
时间:
2012-03-07 14:15
标题:
shell脚本下的for,while,until循环运用
#!/bin/bash
for file
do
if [ -f $file ]
then
echo "$file为普通文件"
elif [ -d $file ]
then
echo "$file为目录文件"
elif [ -b $file ]
then
echo "$file为块设备文件"
elif [ -c $file ]
then
echo "$file为字符设备文件"
elif [ -h $file ]
then
echo "$file为链接文件"
else
echo "没有这个文件类型"
fi
done
//以上是用for循环判断是啥文件。-f为普通文件,-d为目录文件,-b为块设备文件,-c为字符设备文件,-h为链接文件。
#!/bin/bash
while true
do
let s=$s+1
echo $s
if [ $s -gt 200 ]
then
break;
fi
done
//条件满足执行循环判断
#!/bin/bash
s=1
until [ $s -gt 100 ]
do
let s=$s*2
echo $s
done
//条件满足退出循环判断
作者:
mpstat
时间:
2012-03-07 14:31
消灭0回复
作者:
zooyo
时间:
2012-03-07 20:41
提示:
作者被禁止或删除 内容自动屏蔽
作者:
好人家
时间:
2012-03-08 09:37
谢谢LZ,学习了。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2