Re: getting weird output out of 'echo' w/args
On Thu, 30 May 2013 08:53:48 +0300, Pierre Gaston pierre.gas...@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.
Re: getting weird output out of 'echo' w/args
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...@gmx.com wrote: On Thu, 30 May 2013 08:53:48 +0300, Pierre Gaston pierre.gas...@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.
Re: getting weird output out of 'echo' w/args
On Thu, 30 May 2013 16:56:36 +0800, Chris Down ch...@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.
Re: getting weird output out of 'echo' w/args
That's... why I said he was unintentionally doing postincrement... On 30 May 2013 17:04, Davide Brini dave...@gmx.com wrote: On Thu, 30 May 2013 16:56:36 +0800, Chris Down ch...@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.
Re: getting weird output out of 'echo' w/args
On Thu, May 30, 2013 at 12:04 PM, Davide Brini dave...@gmx.com wrote: On Thu, 30 May 2013 16:56:36 +0800, Chris Down ch...@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. ok sorry for not having try my example, my point is that it was not assigning to a[0] because of the nullglob and that this one can be hard to spot
Re: getting weird output out of 'echo' w/args
On Thu, 30 May 2013 17:06:08 +0800, Chris Down ch...@chrisdown.name wrote: That's... why I said he was unintentionally doing postincrement... Doh! Indeed you said that. Apologies for reading too fast. -- D.
Re: getting weird output out of 'echo' w/args
Pierre Gaston wrote: ok sorry for not having try my example, my point is that it was not assigning to a[0] because of the nullglob and that this one can be hard to spot --- Generally don't feel good about that op except in very narrow circumstances...for exactly those types of reasons...what you can't see CAN hurt you! ;-)
Re: getting weird output out of 'echo' w/args
On 30 May 2013 17:59, Linda Walsh b...@tlinx.org wrote: Generally don't feel good about that op except in very narrow circumstances...for exactly those types of reasons...what you can't see CAN hurt you! ;-) It doesn't have anything to do with the operator, it's to do with the usage of square brackets to indicate the index.