[Top][All Lists]

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

Re: unsigned int for loop in bash

From: Mathieu Malaterre
Subject: Re: unsigned int for loop in bash
Date: Mon, 3 Feb 2014 14:38:08 +0100

On Mon, Feb 3, 2014 at 2:22 PM, Greg Wooledge <address@hidden> 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.


reply via email to

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