RHCE作业3 shell编程

1、写一个 bash脚本以输出数字 0 到 100 中 7 的倍数(0 7 14 21...)的命令。

利用seq生成一百个数 使用if语句判断是否能整除7 如果能 就是7的倍数:

#!/bin/bash
#########################
#File name:seven.sh
#Created time:2023-12-22 21:25:58
#Description:
#########################
for i in `seq 100`
do
	if [ $((i%7)) -eq 0 ];then
	echo $i
	fi
done

方法2: 利用while循环 直到 7倍的i大于 100 停止循环

#!/bin/bash
#########################
#File name:seven2.sh
#Created time:2023-12-22 21:35:11
#Description:
#########################
i=1
while [ $[ 7*i ] -lt 100  ]
do

	echo $[ 7*i ] 
	let i++
done


2、写一个 bash脚本以统计一个文本文件 nowcoder.txt中字母数小于8的单词。
示例:
假设 nowcoder.txt 内容如下:
how they are implemented and applied in computer

采用双层循环 外层while循环读取文件 内层for 循环 将内容以列表形式读出

#!/bin/bash
#########################
#File name:read.sh
#Created time:2023-12-22 21:40:01
#Description:
#########################
while read line
do
	for i in $line
	do
		let sum++
	done

done < nowcoder.txt
echo "the words number is $sum"


3、写一个 bash脚本以实现一个需求,去掉输入中含有this的语句,把不含this的语句输出
示例:
假设输入如下:
that is your bag
is this your bag?
to the degree or extent indicated.
there was a court case resulting from this incident
welcome to nowcoder
你的脚本获取以上输入应当输出:
that is your bag
to the degree or extent indicated.
welcome to nowcoder

将输入读入到文件中 然后对文件grep过滤 得到结果

#!/bin/bash
#########################
#File name:nothis.sh
#Created time:2023-12-22 21:53:53
#Description:
#########################
read -p "if you want to stop you can input yes" input
while [[ "$input"x != "yes"x ]]
do	
	read  input
	echo $input >> nothis.txt 
done
grep -wv "this" nothis.txt
echo > nothis.txt

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值