【问题标题】:how to get parameters from command line in unix script [duplicate]如何从unix脚本中的命令行获取参数[重复]
【发布时间】:2013-02-18 07:10:33
【问题描述】:

我必须在 unix 中编写脚本。

当我这样称呼它时:

./check -l word1 -c word2,

我需要从脚本内部获取与命令 -l 和 -c 一起使用的单词。

【问题讨论】:

  • @Blender 我假设是 bash shell。

标签: unix command-line-arguments


【解决方案1】:

使用getopts,如以下脚本所示:

#!/bin/bash

while getopts l:c: option
do
    case "$option" in
        l) 
           loption="$OPTARG"
           ;;
        c)
           coption="$OPTARG"
           ;;
    esac
done

echo "L is: $loption"
echo "C is: $coption"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-10-26
    • 2013-11-08
    • 2017-03-16
    • 2020-07-11
    • 2012-06-26
    • 1970-01-01
    • 2020-02-23
    相关资源
    最近更新 更多