【问题标题】:Unix menu shell script: adding, listing, and extracting files to .tarUnix 菜单 shell 脚本:将文件添加、列出和提取到 .tar
【发布时间】:2013-12-10 04:48:20
【问题描述】:

我正在尝试创建一个基于菜单的脚本,它有 3 个选项 1. 将文件添加到 .tar 2.列出.tar的内容 3.解压tar文件内容

这是我目前所拥有的。我还是 unix 新手,所以是的。

#!/bin/sh
#script2

PS3='Enter your choice: '
options=("Option 1: Add file to .tar" "Option 2: List contents of .tar" "Option 3: Extract         contents"$
select opt in "${options[@]}"
do
    case $opt in
            "Option 1")
                    echo "you chose choice 1"
                    tar -rf file.tar file2add
                    ;;
            "Option 2")
                    echo "you chose choice 2"
                    tar -tf file.tar
                    ;;
            "Option 3")
                    echo "you chose choice 3"

                    ;;
            "Quit")
                    break
                    ;;
            *) echo invalid option;;
    esac
done

[IMG]http://i42.tinypic.com/29gen0o.png[/IMG]

【问题讨论】:

  • Stackoverflow 支持语法高亮。你能把你的代码放在你的帖子里吗?还有,你有什么问题?
  • 好吧,我试图获得执行上述功能的选项,但我一直认为这是一个无效的选项。

标签: shell unix menu terminal tar


【解决方案1】:

除非您真的希望脚本以最少的依赖项工作(即仅与 sh 一起使用),否则请考虑使用 dialog 程序,这样可以更轻松地编写文本模式菜单。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-26
    • 1970-01-01
    • 1970-01-01
    • 2011-05-12
    • 1970-01-01
    • 1970-01-01
    • 2012-09-17
    • 1970-01-01
    相关资源
    最近更新 更多