养生
shellif(shell编程之流程控制--if 语句)

作用:执行过程的自动化智能化的选择及处理,让重复操作跟聪明一些

if 条件

语句

扩展 “;” 分号表示两个两个命令写在一行。互不影响。

[root@xuegod63 test]# ls /optt ; ls

example01.sh expr.sh read.sh z1.sh z.sh

[root@xuegod63 test]# ls /optt && ls

# &&为前一个命令不执行,后一个命令也不执行

1: 语法

命令1

命令2:

【例】 if else的用法

#!/bin/bash

/bin/ls

pwd

执行结果:

[root@xuegod63 test]# ./else.sh

2: if elif/else 多分支的联合

-o 或 || : 逻辑或 。 两个条件有一个成立 ,结果为真

4 语法

命令1

elif 条件2 ; then

elif 条件3 ; then

命令3

命令4

Fi

.6 综合实例: 测试文件类型

#!/bin/bash

read file_name

echo " $file_name is a dir"

echo " $file_name is file"

echo " $file_name is a device file"

echo " $file_name is an unknow file "

fi


顶一下()     踩一下()

热门推荐

发表评论
0评