shell 脚本中的if else
2017-09-11 10:39
253 查看
shell 中的脚本判断,通常用:
if ....; then
....
elif ....; then
....
else
....
fi
其中if 后面的判断,有以下几种形式。
[ -f "somefile" ] :判断是否是一个文件
[ -x "/bin/ls" ] :判断/bin/ls是否存在并有可执行权限
[ -n "$var" ] :判断$var变量是否有值
[ "$a" = "$b" ] :判断$a和$b是否相等
例如:
if ....; then
....
elif ....; then
....
else
....
fi
其中if 后面的判断,有以下几种形式。
[ -f "somefile" ] :判断是否是一个文件
[ -x "/bin/ls" ] :判断/bin/ls是否存在并有可执行权限
[ -n "$var" ] :判断$var变量是否有值
[ "$a" = "$b" ] :判断$a和$b是否相等
例如:
相关文章推荐
- Shell脚本语法-- if/then/elif/else/fi
- shell脚本嵌套if else
- shell 脚本 if elseif else
- Shell脚本语法-- if/then/elif/else/fi
- 【Shell脚本学习16】Shell if else语句
- shell 脚本 if then else fi
- Shell脚本语法-- if/then/elif/else/fi
- shell 脚本编写 if else then
- Linux--Shell脚本(二)条件判断之if else
- shell 脚本 if elseif else
- Shell脚本语法--if/then/elif/else/fi
- Shell脚本if else语句小结
- shell脚本学习之if..else用法
- Shell脚本语法-- if/then/elif/else/fi
- shell脚本编程-使用结构化命令(if/else)(转)
- shell脚本学习之if..else用法
- 第五章 shell 机构化脚本【if-else-fi】
- Linux-Shell脚本编程-学习-5-Shell编程-使用结构化命令-if-then-else-elif
- Shell脚本if else语句小结
- SHELL脚本语句 if、for、while、case 图示