bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: equivalent of Linux readlink -f in pure bash?


From: Stephane CHAZELAS
Subject: Re: equivalent of Linux readlink -f in pure bash?
Date: Wed, 10 Aug 2011 11:47:58 +0100
User-agent: slrn/pre1.0.0-18 (Linux)

2011-08-10, 12:00(+02), Bernd Eggink:
[...]
> function f
> {
>      local OPTIND=1
>
>      echo "\$1=$1"
> }
>
> while getopts "abcdefg" opt
> do
>      echo "opt=$opt"
>      f $opt
> done
> --------------------------------
>
> Calling the sript like this works fine:
>       script -a -b -c
>
> But calling it like this leads to an endless loop:
>       script -abc
[...]
> However, this also loops endlessly. The reason is most likely that bash 
> maintains an additional internal variable holding the index of the 
> current character, relative to the current word. While this variable is 
> not directly accessible by the user, it is set to 0 whenever OPTIND is 
> assigned a value.
[...]

That would be a bug in bash in my opinion. If OPTIND is marked
local to the function, it shouldn't affect the behavior of
parent contexts.

Note that that bug is also in ksh93, pdksh, mksh and posh
(though slightly different in that one), but not in ash nor zsh.

Note that if you set OPTIND local, you probably want to do the
same for OPTARG (and maybe OPTERR).

-- 
Stephane



reply via email to

[Prev in Thread] Current Thread [Next in Thread]