bug-bash
[Top][All Lists]
Advanced

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

Re: getting weird output out of 'echo' w/args


From: Chris Down
Subject: Re: getting weird output out of 'echo' w/args
Date: Thu, 30 May 2013 16:56:36 +0800

Pierre is referring to the fact that [i++] is evaluated as a glob by
the shell, the reason it doesn't work is because $i is postincremented
instead of preincremented. You can see what he means here:

$ shopt -u nullglob
$ i=0
$ while read a[++i]; do
>     echo "${a[i]}"
> done <<< hello
hello
$ shopt -s nullglob
$ while read a[++i]; do
>     echo "${a[i]}"
> done <<< hello

$



On 30 May 2013 16:49, Davide Brini <dave_br@gmx.com> wrote:
> On Thu, 30 May 2013 08:53:48 +0300, Pierre Gaston <pierre.gaston@gmail.com>
> wrote:
>
>> Missing quotes around [ ]  can be nasty eg
>>
>> #!/bin/bash
>> shopt -s nullglob # sounds a good idea!
>> .....
>> .....
>> i=0
>> while read a[i++]; do
>>   echo "${a[i]}" #  why oh why nothing is printed!
>> done <<< "hello"
>
> It seems to me this has nothing to do with missing quotes around [ ], or I
> don't get what you mean.
>
> --
> D.
>



reply via email to

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