rhce第三次作业

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

自动生成脚本文件说明

[root@localhost ~]# vim /root/.vimrc

创建一个test文件夹,在vim test1.sh中编写bash脚本

#!/bin/bash
#########################
#File name:test1.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2023-12-17 16:14:24
#Description:
#########################
for((i=0;i<=100;i++))
do
        if [ "$((i%7))" -eq 0 ]
        then
                echo $i
        fi
done

输入ls -l  test1.sh查看,编辑使文件可读,可写,可执行

[root@localhost test]# ls -l  test1.sh 
-rw-r--r--. 1 root root 243 12月 17 16:16 test1.sh
[root@localhost test]# chmod a+rx test1.sh

最后执行脚本

[root@localhost test]# ./test1.sh
0
7
14
21
28
35
42
49
56
63
70
77
84
91
98

2.写一个 bash脚本以统计一个文本文件 nowcoder.txt中字母数小于8的单词。

在vim  nowcoder.txt中写一个bash脚本

内容how they are implemented and applied in computer

[root@localhost test]# cat nowcoder.txt
how they are implemented and applied in computer

在脚本test3.sh中统计字母小于8

[root@localhost test]# vim test3.sh
#!/bin/bash
#########################
#File name:test3.sh
#Version:v1.0
#Email:admin@test.com
#Created time:2023-12-17 17:11:58
#Description:
#########################
for i in $(cat nowcoder.txt)
do
    if (($(echo $i | wc -L)<8)); then
        echo -e "$i"
    fi
done

执行

[root@localhost test]# chmod a+rx test3.sh
[root@localhost test]# ./test3.sh
how
they
are
and
applied
in

3.写一个 bash脚本以实现一个需求,去掉输入中含有this的语句,把不含this的语句输出

[root@localhost test]# vim ceshi.txt
[root@localhost test]# vim test5.sh
[root@localhost test]# chmod a+rx test5.sh
[root@localhost test]# ./test5.sh
that is your bag
to the degree or extent indicated.
welcome to nowcoder

  • 8
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值