Linux Shell经典面试题(其三)

Linux Shell经典面试题(其三)

参考:http://blog.csdn.net/hiyun9/article/details/52057255

1.打印选择菜单,一键安装Web服务:
[root@oldboyscripts]# sh menu.sh

1.[install lamp]

2.[install lnmp]

3.[exit]

pls input the num you want:

要求:
1>、当用户输入1时,输出“startinstalling lamp.”然后执行/server/scripts/lamp.sh,脚本内容输出”lampis installed”后退出脚本;
2>、当用户输入2时,输出“startinstalling lnmp.”然后执行/server/scripts/lnmp.sh输出”lnmpis installed”后退出脚本;
3>、当输入3时,退出当前菜单及脚本;
4>、当输入任何其它字符,给出提示“Input error”后退出脚本。
5>、要对执行的脚本进行相关条件判断,例如:脚本是否存在,是否可执行等。

############选择执行脚本的脚本编写##############

$ vi menu.sh

#!/bin/bash

echo "1.[install lamp]"
echo "2.[install lnmp]"
echo "3.[exit]"

read -t 30 -p "Please input tut the num you want:" a

case $a in
    1)
        if
            [-f lamp.sh ];then
            ./lamp.sh
            sleep 3
            echo "lamp is installed!"
        else
            echo "no lamp.sh!"
        fi
    ;;

    2)
        if 
            [-f lnmp.sh ];then
            ./lnmp.sh
            sleep 3
            echo "lnmp is installed!"
        else
            echo "no lnmp.sh!"
        fi
    ;;

    3)
        exit 0
    ;;

    *)
        echo "Input error"
        exit 0
esac

2.用shell处理以下内容

1>、按单词出现频率降序排序!
2>、按字母出现频率降序排序!

the squid project provides a number of resources toassist users design,implement and support squid installations. Please browsethe documentation and support sections for more infomation

$ cat test
the squid project provides a number of resources toassist users design,implement and support squid installations.Please browsethe   
documentation and support sections for more infomation 
############按单词出现频率降序排序的脚本编写##############

$ vi by-word-num-sort-desc.sh

#!/bin/bash

sed -i 's/\,\|\./ /g' test

for i in `cat test`
do
    echo $i
done

# 执行此脚本

$ sh ./by-word-num-sort-desc.sh |sort|uniq -c |sort -r
############按字母出现频率降序排序的脚本编写##############

$ vi by-char-num-sort-desc.sh

#!/bin/bash

sed -i 's/\,\|\./ /g' test

for i in `cat test`
do
    for j in `echo $i`
    do
        echo $j | awk -F '' '{for(i=1;i<=NF;i++)print $i}'
    done
done

# 执行此脚本

$ sh ./by-char-num-sort-desc.sh |sort|uniq -c |sort -nr
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值