[Top][All Lists]

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

Re: Crash on large brace expansion

From: Léa Gris
Subject: Re: Crash on large brace expansion
Date: Thu, 15 Jul 2021 17:28:04 +0200
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

Le 15/07/2021 à 16:36, Gabríel Arthúr Pétursson écrivait :
Hi all,

Executing the following results in a fierce crash:

    $ bash -c '{0..255}.{0..255}.{0..255}.{0..255}'

Brace expression expands all the value in memory.

Here you are actually telling Bash to expand 256⁴ or 4294967296 42 Billion entries.

{0..255}.{0..255}.{0..255}.{0..255} expands all the IPv4 address space. It cannot fit in any current home PC memory.

The crash is due to out of memory and is wholly expected.

Use index loops instead:

for ((a=0; a<=255; a++)); do
  for ((b=0; b<=255; b++)); do
    for ((c=0; c<=255; c++)); do
      for ((d=0; d<=255; d++)); do
        printf '%d.%d.%d.%d\n' "$a" "$b" "$c" "$d"

Léa Gris

reply via email to

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