SHELL/作业/2024/6/25

 终端输入两个数,判断两数是否相等,如果不相等,判断大小关系

 #!/bin/bash
 a=$1
 b=$2              
 if [ $a -eq $b ]
 then 
     echo "a=b"
 elif [ $a -gt $b ]
 then
     echo "a>b"
 else
     echo "a<b"
 fi

 

2.已知网址www.hqyj.com,使用expr截取出www、hqyj、com,不能使用cut,不能出现数字

#!/bin/bash

str1="www.hqyj.com"

# 截取 www
a=$(expr match "$str1" 'www')
b=$(expr index "$str1" 'w')
d=$(expr substr "$str1" $b $a)
echo $d

# 截取 hqyj
a2=$(expr index "$str1" 'j')
f=$(expr index "$str1" '.')
len=$((a2-f))
b2=$(expr index "$str1" 'h')
d2=$(expr substr "$str1" $b2 $len)
echo $d2

# 截取 com
a3=$(expr match "$str1" '.*\.')
b3=$(expr index "$str1" 'c')
d3=$(expr substr "$str1" $b3 $a3)
echo $d3

3,思维导图 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值