【发布时间】:2014-07-29 04:12:34
【问题描述】:
谁能检查这段代码 sn-p 并告诉我为什么当我用 -p abcdef 调用这个脚本时 $OPTARG 从来没有传入的参数值?
# Process command-line options passed as switches to this script
while getopts "ph:" option; do
case "$option" in
p)
{
if [ -n "$OPTARG" ]; then
echo
echo "##### SCRIPT ERROR: You failed to provide a host prefix. #####"
echo
usage
break
else
echo "Setting host prefix to '$OPTARG'"
echo
HOST_PREFIX=$OPTARG
fi
} ;;
h) usage ;;
'?') usage ;;
*) break ;;
esac
done
shift "$((OPTIND-1))" # Shift off the options and optional --.
【问题讨论】: