shell中if使用方法

 时间:2026-02-14 03:03:05

1、if的语法结构

if [ condition ]

then 

    statements 

[elif condition 

    then statements. ..] 

[else 

    statements ] 

fi

shell中if使用方法

2、整数比较

shell中if使用方法

3、字符串比较

shell中if使用方法

4、权限判断,用于判断文件对当前用于的权限

-r  有读的权限

-w  有写的权限

-x  有执行的权限

5、if对于文件的判断

shell中if使用方法

6、脚本实例

脚本一:

#!/bin/sh

echo "Please input a integer:"

read integer1

if [ "$integer1" -lt 30 ]

then echo "The integer which you input is lower than 30."

fi

脚本二:

if [ -f 023.txt ];then

echo "file is exist"

else 

touch 023.txt

fi

  • 叫我大掌柜怎么钓鱼
  • Visio怎么样创建方向图
  • Word2007域简介及什么是域代码
  • 韩剧复仇笔记2男主角是谁
  • 英雄联盟幻翎洛与逆羽霞
  • 热门搜索
    今年流行什么鞋 自来卷适合什么发型 毋庸置疑的意思 人乳头瘤病毒是什么意思 故人是什么意思 欧巴桑是什么意思 逆战手游什么时候出 秋天穿什么 怨恨的意思 原则是什么意思