linux教程:shell脚本基本语法

 时间:2024-10-25 15:45:36

1、if判断语句的写法是这样:#!/bin/basha=1;if [ $a -lt 10 ]; then echo "ok"fi其中a=1中间一定不能有空格,如果a<10打印ok。

linux教程:shell脚本基本语法

2、保存文件。然后给文件授权:chmod +x test.sh然后执行脚本./test.sh

linux教程:shell脚本基本语法

3、字符串相等:#!/bin/basha="hello"if [ $a = "hello" ]; then echo "ok"fi

linux教程:shell脚本基本语法

4、字符串匹配:注意比较条件中是[[ 条件 ]],否则会报错。例如:#!/bin/basha="he造婷用痃llo"if [[ $a =~ "hello" ]]; then echo "match ok"else echo "match fail"fi

linux教程:shell脚本基本语法

5、另一种字符串比较方法:#!/bin/basha屏顿幂垂="hello"if [[ $a == *"he造婷用痃llo"* ]]; then echo "match ok"else echo "match fail"fi

linux教程:shell脚本基本语法
  • 如何设置xshell编码
  • eclipse如何配置tomcat6
  • docker镜像加速方法
  • weblogic 配置数据源(以oracle为例)
  • Oracle开发工具:[1]SQL*Plus工具
  • 热门搜索
    泡萝卜怎么做才好吃而且脆酸甜 cpu使用率100怎么办 怎么重装系统 电脑风扇声音大怎么办 耳的笔顺怎么写 减号怎么打 怎么创建苹果id 路由器怎么设置密码 拂怎么读 命运多舛怎么读