今天给各位分享access数据库if语句(shell编程之流程控制的知识,其中也会对access数据库if语句(shell编程之流程控制进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
作用:执行过程的自动化智能化的选择及处理,让重复操作跟聪明一些
if 条件
扩展 “;” 分号表示两个两个命令写在一行。互不影响。
【例】 “; “和“&&“在多命令使用时候的区别
[root@xuegod63 test]# ls /optt ; ls
ls: cannot access /optt: No such file or directory
example01.sh expr.sh read.sh z1.sh z.sh
# 分号为前后命令没有关系
[root@xuegod63 test]# ls /optt && ls
ls: cannot access /optt: No such file or directory
# &&为前一个命令不执行,后一个命令也不执行
3 if /else 的主要使用
1: 语法
if 条件1 ; then

【例】 if else的用法
[root@xuegod63 test]# cat else.sh
#!/bin/bash
if [ -x /etc/passwd ] ; then #判断是否为可执行文件
/bin/ls
执行结果:
[root@xuegod63 test]# chmod +x else.sh
[root@xuegod63 test]# ./else.sh
/root/test
2: if elif/else 多分支的联合
-a 或 && : 逻辑与,仅当两个条件都成立时,结果为真
-o 或 || : 逻辑或 。 两个条件有一个成立 ,结果为真
4 语法
if 条件1 ; then
elif 条件2 ; then
elif 条件3 ; then
18.7.5 if elif/else 多分支的结构图
.6 综合实例: 测试文件类型
[root@xuegod63 test]# cat elif.sh
#!/bin/bash
echo "input a file name:"
read file_name
if [ -d $file_name ] ; then
echo " $file_name is a dir"
elif [ -f $file_name ] ; then
echo " $file_name is file"
elif [ -c $file_name -o -b $file_name ] ; then
echo " $file_name is a device file"
else
echo " $file_name is an unknow file "
OK,本文到此结束,希望对大家有所帮助。