命令行菜单选项

时间:2012-10-30 15:26:42

标签: bash scripting

我一直试图让我的菜单工作,但似乎它一次只接受一个参数/选项,我怎么能让它接受多个选项?

#!/bin/bash

##### Main

function usage
{
    echo "
usage: infinidb [[-f file ] [-i] | [-h]]  name ...
}

        while [ "$1" != "" ]; do
        case $1 in
            -f | --file )           shift
                                    filename=$1
                                    ;;
            -i |  )                 filename2=$2
                                    ;;
            -h | --help )           usage
                                    exit
                                    ;;
            * )                     usage
                                    exit 1
        esac
        shift
    done

            echo $filename 
            echo $filename2

运行脚本时

以下输出显示show

./ script.sh -f apple -i tree

苹果树

1 个答案:

答案 0 :(得分:1)

这对我有用

#!/bin/bash

    while [ "$1" != "" ]; do
    case $1 in
        -f | --file )           shift
                                filename=$1
                                ;;
        -i )                 filename2=$2
                                ;;
    esac
    shift
done

        echo $filename 
        echo $filename2

-i | )

只出现问题
相关问题