现在的位置: 首页 > 综合 > 正文

bash流程操作语法

2013年10月27日 ⁄ 综合 ⁄ 共 746字 ⁄ 字号 评论关闭

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存在

抱歉!评论已关闭.