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"
      done
    done
  done
done

--
Léa Gris


Reply via email to