一般来说,我们是用echo来输出的,可是一行还好说,多行就比较麻烦啦,这时候我们可以用cat命令,如下
#!/bin/bash
cat <<END
1.[install dhcp]
2.[install dns]
3.[install rsync]
4.[install lnmp]
please input you want to install of number:
END
我们执行的效果如下:
[root@zhouyu shell]# sh 03.sh
1.[install dhcp]
2.[install dns]
3.[install rsync]
4.[install lnmp]
please input you want to install of number:
下面我们来写一个分级菜单的脚本,如下
#!/bin/bash
cat <<END
1.[install dhcp]
2.[install dns]
3.[install rsync]
4.[install lnmp]
please input you want to install of number:
END
read a
echo "you input the number is $a"
[ $a -eq 1 ] && {
yum install dhcpd -y
}
下面是执行的效果图
[root@zhouyu shell]# sh 03.sh
1.[install dhcp]
2.[install dns]
3.[install rsync]
4.[install lnmp]
please input you want to install of number:
1
you input the number is 1
Loaded plugins: fastestmirror, refresh-packagekit, security
Determining fastest mirrors
* base: mirrors.zju.edu.cn
* extras: mirrors.zju.edu.cn
* updates: mirrors.zju.edu.cn
base | 3.7 kB 00:00
extras | 3.4 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 3.7 MB 00:03
Setting up Install Process
No package dhcpd available.
Error: Nothing to do
[root@zhouyu shell]#
上面的原因是因为我没有配置yum,不过这说明我们的脚本没有问题
本文出自 “爱周瑜” 博客,请务必保留此出处http://izhouyu.blog.51cto.com/10318932/1890995
原文:http://izhouyu.blog.51cto.com/10318932/1890995