On Thu, Jan 10, 2019 at 11:59 AM Chet Ramey <[email protected]> wrote:
> On 1/10/19 2:52 PM, Jeremy wrote: > >> This command line should run forever: > > >> i=0; while [ "_$(echo echo '$1' | . /dev/stdin yes)" = "_yes" ]; \ > > do echo -n .; ((i++)); done; printf "\n%s\n" $i > > >> When I run it, it usually terminates with $i much less than 1,000. > > > >... The thing is I do not have control over which > > versions of bash people use to run the script, so I need a workaround. > > > > ... > > I am not happy with the obvious workaround of sourcing a file instead of > > /dev/stdin. > > Have you considered reading stdin into a string (if it's one line) or an > array (if it's more) and using `eval' on it? That obviously works better > if it's one line, but could be made to work on multiple lines. > > We are trying to determine if the current shell supports passing positional arguments to a script sourced by dot (.), and we are trying to do it in a way that will work under pretty much any shell. If you can show me how to do that with eval, then that would be great, even though in general I hate to ship a script that uses eval. The best workaround I have come up with so far is to generate a more complex script that outputs either "yes" or "no" and then retry if it gets no output, but then I have to put a limit on retries to avoid a possible infinite loop and handle the case where the loop terminates without an answer. My hope is that if we understand the source of the bug we can create a more straightforward work around.
