Re: $OPTIND varibale value is different from sh

2018-06-20 Thread Chet Ramey
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

Re: $OPTIND varibale value is different from sh

2018-06-20 Thread Martijn Dekker
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

Re: $OPTIND varibale value is different from sh

2018-06-20 Thread Martijn Dekker
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

Re: $OPTIND varibale value is different from sh

2018-06-20 Thread Ilkka Virta
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

Re: $OPTIND varibale value is different from sh

2018-06-20 Thread Greg Wooledge
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 <-- >

$OPTIND varibale value is different from sh

2018-06-20 Thread Hyunho Cho
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