您的位置:首页 > 运维架构 > Shell

bash流程操作语法

2008-03-26 15:46 337 查看
1: if 条件语句

(1) if condition;
then command;
fi

(2) if condiont;
then command
else
command
fi

(3) if condition;then
command
elif condition;then
command;
else
comand;
fi

(4)

case express in case1)
command_list;;
case2)
command_list;;
esac

例:

case $space in
[1-6]*)
message = ""
;;
[7-8]*)
message=""
99)
message=""
;;
*)
message=""
esac

2 for语句

(1)for name in [in word]; do list;done

for filename in `ls`;

do

cat $filename

done
(2)for((expr1;expr2;expr3)); do list;done

for(i=0;i<10;i++);

do

echo $i

done

其它

$# 参数的总数, $? 返回给父进程的退出状态码

条件判断:

[-d 文件] 文件存在且是一个目录
[-e 文件] 文件存在
[-f 文件] 文件存在且为普通文件
[-h 文件] 符号链接文件 [L file]
[-p file] 管道
[-s file] 比零字节大的文件
[-r file] 存在且是可读
[-w file] 存在且可写
[-x file] 可执行
[-S file) socket file
[-z string] string长度为零
[-n string] string长度非零
[file1 nt file2] file1比file2新,或者file1 存在而file2不存在
[file1 ot file2] file1比file2旧,或者file1不存在面file2存在
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: