#!/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 testDirfor$dir和0for $it,而不仅仅是testDirfor$dir和2for $it。我怎样才能得到预期的行为?
./test.sh -pi 2 testDir
true 0 2 testDir