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工具
  • 热门搜索
    海尔空调质量怎么样 腰椎间盘突出怎么治 不粘锅粘锅了怎么办 怎么在手机上赚钱 怎么投简历 家风家训怎么写 微信怎么发文字 苹果音乐怎么下载 怎么用键盘关机 耳膜破了怎么办