Re: unsigned int for loop in bash

2014-02-03 Thread Greg Wooledge
On Sat, Feb 01, 2014 at 05:36:17PM +0100, Mathieu Malaterre wrote:
> #!/bin/bash
> 
> for i in {0..4294967295}; do
>   echo $i
> done

Others said not to do that.  They are correct, but they didn't tell you
what to do instead.

for ((i=0; i<=4294967295; i++)); do
  echo $i
done

The brace expansion form actually expands to the full list of strings,
all at once, which means they are all stored in memory at once.  Most
computers don't have that much memory (something like 40 GB to hold
your 4 billion strings, of variable length from 2 to 11 bytes each).
The C-style for loop doesn't generate them all at once, so it only uses
a few bytes of memory.



Re: unsigned int for loop in bash

2014-02-03 Thread Mathieu Malaterre
On Mon, Feb 3, 2014 at 2:22 PM, Greg Wooledge  wrote:
> On Sat, Feb 01, 2014 at 05:36:17PM +0100, Mathieu Malaterre wrote:
>> #!/bin/bash
>>
>> for i in {0..4294967295}; do
>>   echo $i
>> done
>
> Others said not to do that.  They are correct, but they didn't tell you
> what to do instead.
>
> for ((i=0; i<=4294967295; i++)); do
>   echo $i
> done
>
> The brace expansion form actually expands to the full list of strings,
> all at once, which means they are all stored in memory at once.  Most
> computers don't have that much memory (something like 40 GB to hold
> your 4 billion strings, of variable length from 2 to 11 bytes each).
> The C-style for loop doesn't generate them all at once, so it only uses
> a few bytes of memory.

Thanks ! Problem solved.

I still believe the SIGSEGV should be handled in a more graceful way,
at least on a Linux kernel.

-- 
Mathieu



Re: Associative array assignment crashes Bash interpreter

2014-02-03 Thread Chet Ramey
On 2/3/14 2:06 AM, Chris Down wrote:
> First of all, please fix your broken From header. It should be
> b...@franklin.gtkcentral.net when you are addressing the wider Internet,
> not ben@franklin.
> 
> On 2013-12-13 05:25:17 -0500, ben@franklin wrote:
>> Description:
>>  The included scripts generate a "division by zero" and "recursion level 
>> exceeded" errors. Confirmed in
>> Bash 4.2.45, 4.1.5, and 4.1.2.
> 
> If you had searched the archives, you would know that this exact
> discussion was had only days ago. In fact, it seems it was you that sent
> it. Please don't repeatedly send the same messages to this list.

I'm going to assume from the date and the Received: headers that this is
just a case of a mail queue getting flushed.  The message looks like it
sat in a queue for around 50 days.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Associative array assignment crashes Bash interpreter

2014-02-03 Thread Chris Down
On 2014-02-03 08:52:20 -0500, Chet Ramey wrote:
> I'm going to assume from the date and the Received: headers that this is
> just a case of a mail queue getting flushed.  The message looks like it
> sat in a queue for around 50 days.

Ah, I didn't see the date on the original mail. My bad.


pgpbZ4oIbkGTt.pgp
Description: PGP signature