简体   繁体   English

Lubuntu中的基本菜单BASH脚本

[英]Basic menu BASH script in Lubuntu

I am creating a basic menu driven BASH script with 6 options, I was wondering if someone can give me a basic template of the script? 我正在创建具有6个选项的基本菜单驱动BASH脚本,我想知道是否有人可以给我该脚本的基本模板? #!/bin/bash Option 1) Option 2) Option 3) Option 4) Option 5) Option 6) Exit #!/ bin / bash选项1)选项2)选项3)选项4)选项5)选项6)退出

Try the select statement. 尝试选择语句。 Example and template: 示例和模板:

#!/bin/bash

select choice in opt1 opt2 opt3 opt4 opt5 exit
do
        case $choice in 
        opt1)   
                sl;
                fortune|cowsay -d;
                break;;
        opt2)   
                cd desktop/;
                mkdir textfiles;
                cd textfiles;
                touch 1.txt 2.txt 3.txt;
                cd ..;
                tar-cvf textfiles.tar textfiles/;
                break;;
        opt3)   
                echo 'You chose opt3';;
        opt4)   
                echo 'You chose opt4';;
        opt5)   
                echo 'You chose opt5';;
        exit)
                break;;
        *)
                echo 'Invalid option';;
        esac
done

I have inserted opt1 and opt2 as examples. 我已插入opt1和opt2作为示例。 Remember to use break;; 记住要使用break;; if you want to exit the menu loop and choose better names than optN for the options. 如果要退出菜单循环并为选项选择比optN更好的名称。

Edit: I just copied opt1 and opt2 from your question. 编辑:我只是从您的问题中复制了opt1和opt2。 I haven't looked into them. 我没有调查他们。 If you need help with them, you should probably ask separate questions. 如果您需要有关他们的帮助,则可能应该询问其他问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM