SHELL脚本菜单 [英] Shell Script for Menu

查看:131
本文介绍了SHELL脚本菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在在linux驱动Shell脚本一个新的菜单,我简化了我的表,只是打招呼,再见,使这个简单的,下面是我的基本菜单布局

I am making a new Menu Driven Shell Script in linux, I have simplified my table to just hello and bye to make this simpler, below is my basic menu layout

# Menu Shell Script
#
echo ----------------
echo     menu
echo ----------------
echo [1] hello
echo [2] bye
echo [3] exit
echo ----------------

基本上我已经在菜单中,我一直在用一些东西玩耍,但最近不能似乎得到任何工作,我是新来这个,我觉得再下一行会

Basically I have the menu, I have been playing around with a few things recently but cant seem to get anything working as I am new to this, I think then next line would be

`read -p "Please Select A Number: " menu_choice`

但我不知道该怎么用变量,什么不可以做。
我想知道,如果有人可以帮助我,code的下位简单地把它打个招呼,当我preSS之一,再见时2 pressed和退出时3,当用户presses 3.这将是这么多AP preciated,因为我已经为天尝试不同的方式和似乎无法得到它的工作。

but I am not sure what to do with the variable and what not. I was wondering if anyone could help me with the next bit of code to simply get it to say hello when I press one, bye when 2 is pressed and exit when 3 when the user presses 3. It would be so much appreciated as I have been trying different ways for days and can't seem to get it to work.

推荐答案

您不需要为回声... 阅读这些反引号

echo "----------------"
echo "    menu"
echo "----------------"
echo "[1] hello"
echo "[2] bye"
echo "[3] exit"
echo "----------------"

read -p "Please Select A Number: " mc
if [[ "$mc" == "1" ]]; then
    echo "hello"
elif [[ "$mc" == "2" ]]; then
    echo "bye"
else
    echo "exit"
fi

修改

showMenu(){

echo "----------------"
echo "    menu"
echo "----------------"
echo "[1] hello"
echo "[2] bye"
echo "[3] exit"
echo "----------------"

read -p "Please Select A Number: " mc
return $mc
}


while [[ "$m" != "3" ]]
do
    if [[ "$m" == "1" ]]; then
        echo "hello"

    elif [[ "$m" == "2" ]]; then
        echo "bye"
    fi
    showMenu
    m=$?
done

exit 0;

这篇关于SHELL脚本菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆