#!/bin/bash
priority=false
it=0
dir=/
while getopts "p:i" option
do
case $option in
i) it=$OPTARG;;
p) priority=true;;
esac
done
if [[ ${@:$OPTIND} != "" ]]
then
dir=${@:$OPTIND}
fi
echo $priority $it $dir
如果我执行它,我会得到2 testDir
for$dir
和0
for $it
,而不仅仅是testDir
for$dir
和2
for $it
。我怎样才能得到预期的行为?
./test.sh -pi 2 testDir
true 0 2 testDir