On 6/20/18 2:09 PM, Martijn Dekker wrote:
> Op 20-06-18 om 13:39 schreef Greg Wooledge:
>> I really don't understand what you're doing here, either. The only
>> use of OPTIND is after the final call to getopts, when there are no
>> more options to process. At that point, OPTIND tells you how many
Op 20-06-18 om 17:45 schreef Ilkka Virta:
$ for sh in dash 'busybox sh' bash ksh93 zsh ; do printf "%-10s: "
"$sh"; $sh -c 'while getopts abcd opt; do printf "$OPTIND "; done;
printf "$OPTIND "; shift $(($OPTIND - 1)); echo "$1" ' sh -a -bcd
hello; done
dash : 2 3 3 3 3 hello
busyb
Op 20-06-18 om 13:39 schreef Greg Wooledge:
I really don't understand what you're doing here, either. The only
use of OPTIND is after the final call to getopts, when there are no
more options to process. At that point, OPTIND tells you how many
times you have to "shift" to get rid of all the op
On 20.6. 15:39, Greg Wooledge wrote:
On Wed, Jun 20, 2018 at 05:16:48PM +0900, Hyunho Cho wrote:
set -- -a -bc hello world
getopts abc opt "$@"
getopts abc opt "$@" # bash = b, 2 <-- different from
"sh"
echo $opt, $OPTIND# sh = b, 3
Since POSIX
On Wed, Jun 20, 2018 at 05:16:48PM +0900, Hyunho Cho wrote:
> set -- -a -bc hello world
>
> echo $OPTIND# sh, bash = 1
>
> getopts abc opt "$@"
> echo $opt, $OPTIND # sh, bash = a, 2
>
> getopts abc opt "$@" # bash = b, 2 <--
> dif
if $OPTIND value start from 1 then i think "-b" $OPTIND should be "3" like sh
but bash print "2"
set -- -a -bc hello world
echo $OPTIND# sh, bash = 1
getopts abc opt "$@"
echo $opt, $OPTIND # sh, bash = a, 2
getopts abc opt "$@" # bash = b, 2