[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 17:06:08 +0800 |
That's... why I said he was unintentionally doing postincrement...
On 30 May 2013 17:04, Davide Brini <dave_br@gmx.com> wrote:
> On Thu, 30 May 2013 16:56:36 +0800, Chris Down <chris@chrisdown.name> wrote:
>
>> 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
>>
>> $
>
> But he was doing postincrement, so it wouldn't have worked anyway, since
> the code was assigning to a[0] and printing a[1].
>
> PS: Better put a
>
> a=()
>
> before each run.
>
> --
> D.
>
- getting weird output out of 'echo' w/args, Linda Walsh, 2013/05/29
- Re: getting weird output out of 'echo' w/args, Chet Ramey, 2013/05/29
- Re: getting weird output out of 'echo' w/args, Linda Walsh, 2013/05/29
- Re: getting weird output out of 'echo' w/args, Pierre Gaston, 2013/05/30
- Re: getting weird output out of 'echo' w/args, Davide Brini, 2013/05/30
- Re: getting weird output out of 'echo' w/args, Chris Down, 2013/05/30
- Re: getting weird output out of 'echo' w/args, Davide Brini, 2013/05/30
- Re: getting weird output out of 'echo' w/args,
Chris Down <=
- Re: getting weird output out of 'echo' w/args, Davide Brini, 2013/05/30
- Re: getting weird output out of 'echo' w/args, Pierre Gaston, 2013/05/30
- Re: getting weird output out of 'echo' w/args, Linda Walsh, 2013/05/30
- Re: getting weird output out of 'echo' w/args, Chris Down, 2013/05/30
- Re: getting weird output out of 'echo' w/args, Linda Walsh, 2013/05/30