Linux--shell练习题

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

vim /shell/homework1.sh
#!/bin/bash
for num in {0..100}
do
        if [[ num%7 -eq o ]];then

                echo $num
        fi
done

执行输出脚本查看输出结果

输出结果:

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

假设 nowcoder.txt 内容如下:
how they are implemented and applied in computer

首先创建一个nowcoder.txt文件,用作测试

vim /test/nowcoder.txt
how they are implemented and applied in computer

 然后配置脚本

vim /shell/homework2.sh
#!/bin/bash
for n in $(cat /test/nowcoder.txt)
do
  if [ `expr length $n` -lt 8 ]
  then
          echo $n
  fi
done

执行脚本查看输出结果

输出结果:

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

首先创建一个测试文件,用来储存输入的内容

vim /test/test1

编写脚本文件

#!/bin/bash
while true
do 
        read -p "input(if you want to stop inputting,please enter stop)" mark
        if [ "$mark" = "stop" ];then
                break
        fi
        echo $mark >> /test/test1
done
echo "Output results"
grep -w this -v /test/test1
echo > /test/test1

执行脚本,查看输出结果

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值