【发布时间】:2013-02-18 07:10:33
【问题描述】:
我必须在 unix 中编写脚本。
当我这样称呼它时:
./check -l word1 -c word2,
我需要从脚本内部获取与命令 -l 和 -c 一起使用的单词。
【问题讨论】:
-
@Blender 我假设是 bash shell。
标签: unix command-line-arguments
我必须在 unix 中编写脚本。
当我这样称呼它时:
./check -l word1 -c word2,
我需要从脚本内部获取与命令 -l 和 -c 一起使用的单词。
【问题讨论】:
标签: unix command-line-arguments
使用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"
【讨论】: