【发布时间】:2013-05-03 16:36:45
【问题描述】:
我正在编写一个可以选择文件并打印特定内容的脚本。例如,
san#./script.sh
Expected Usage : ./script.sh --file1 --dns
(这里检查file1,搜索dns名称并打印。基本上一个参数下有子参数)
我尝试了如下的单个参数/选项:
options=$@
arguments=($options)
index=0;
for argument in $options
do
index=`expr $index + 1`;
case $argument in
-a | --fun1 ) run_function1 ;;
-b | --fun2 ) run_function2 ;;
-c | --fun3 ) run_function3 ;;
esac
done
exit;
[ ${1} ] || helpinfo
任何人都可以建议双参数(子选项)吗?
预期的目标选项:
./script.sh
OPTIONS : ./script.sh -h
./script --fun1 stackoverflow
microsoft
Google
--fun2 Yahoo
基本上每个函数都会查看一个文件。我研究了 getopt 或 getopts,但它没有长选项(--long 是不可能的,相反我们只能使用-l)。但再次不确定子参数。有人可以帮忙吗?
【问题讨论】:
-
我主要不是在寻找子选项。不仅仅是短/长。
标签: linux bash shell unix scripting