温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

打印选择菜单,一键安装Web服务

发布时间:2020-06-22 18:43:53 来源:网络 阅读:1010 作者:粉鱼儿 栏目:MySQL数据库

打印选择菜单,一键安装Web服务:

[root@oldboyscripts]# sh menu.sh 
    1.[install lamp]
    2.[install lnmp]
    3.[install mysql]
    4.[install php]
    5.[exit]
    pls input the num you want:

要求:

1、当用户输入1时,输出“startinstallinglamp.”然后执行/server/scripts/lamp.sh,脚本内容输出"lampis installed"后退出脚本;

2、当用户输入2时,输出“startinstallinglnmp.”然后执行/server/scripts/lnmp.sh输出"lnmpis installed"后退出脚本;

3、当用户输入2时,输出“startinstallingmysql.”然后执行/server/scripts/mysql.sh输出"mysql installed"后退出脚本;

4、当用户输入2时,输出“startinstallingphp.”然后执行/server/scripts/php.sh输出"php installed"后退出脚本;

5、当输入3时,退出当前菜单及脚本;

6、当输入任何其它字符,给出提示“Input error”后退出脚本。

7、要对执行的脚本进行相关条件判断,例如:脚本是否存在,是否可执行等。

解答:

#!/bin/bash
RED_COLOR='\E[1;31m'
GREEN_COLOR='\E[1;32m'
YELLOW_COLOR='\E[1;33m'
BLUE_COLOR='\E[1;34m'
PINK_COLOR='\E[1;35m'
RES='\E[0m'
cat <<EOF   要打印的菜单
1.[install lamp]
2.[install lnmp]
3.[install mysql]
4.[install php]
5.[exit]
EOF
read -p"pls input the num you want:" a   请输入一个参数
case $a in
1)
  echo -e "$BLUE_COLOR startinstalling lamp $RES"    给输出的内容加上颜色
  lampScripts=/server/scripts/lamp.sh
 [-f$lampScripts] && sh $lampScripts|| exit1   判断要执行的lamp文件是否存在
 ;;
 2)
  echo -e "$PINK_COLOR startinstalling lnmp $RES"
  lnmpScripts=/server/scripts/lnmp.sh
  [-f$lnmpScripts] && sh $lnmpScripts|| exit2
 ;;
 3)
  echo -e "$GREEN_COLOR startinstalling mysql $RES"
  mysqlScripts=/server/scripts/mysql.sh
  [-f$mysqlScripts] && sh $mysqlScripts|| exit3
 ;;
 4)
 echo-e "$PINK_COLOR startinstalling php $RES"
 phpScripts=/server/scripts/mysql.sh
  [-f$phpScripts] && sh $phpScripts|| exit4
  ;;
 *)
  echo -e "$RED_COLOR input error $RES"
esac




向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI