Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #14219 > unrolled thread

Re: Sequence Brace Expansion Crash

Started byGreg Wooledge <wooledg@eeg.ccf.org>
First post2018-06-04 09:02 -0400
Last post2018-06-04 09:02 -0400
Articles 1 — 1 participant

Back to article view | Back to gnu.bash.bug

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Sequence Brace Expansion Crash Greg Wooledge <wooledg@eeg.ccf.org> - 2018-06-04 09:02 -0400

#14219 — Re: Sequence Brace Expansion Crash

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2018-06-04 09:02 -0400
SubjectRe: Sequence Brace Expansion Crash
Message-ID<mailman.1111.1528117360.1292.bug-bash@gnu.org>
On Sat, Jun 02, 2018 at 09:18:14PM -0700, Thomas Fischer wrote:
> Repeat-By:
> echo {a..z}{a..z}{a..z}{a..z}{a..z}{a..z}

26^6 = 308915776 words of 6 bytes each, plus however much overhead is
involved in constructing a list of 308915776 strings.

You've probably gone well over 2 GB of virtual memory for this expansion.

When you're trying to a few GB of data to stdout, use nested loops
instead of a single brace expansion that needs to generate the entire
list in memory.

for a in {a..z}; do
  for b in {a..z}; do
    for c in {a..z}; do
      for d in {a..z}; do
        for e in {a..z}; do
          for f in {a..z}; do
            printf '%s%s%s%s%s%s\n' "$a" "$b" "$c" "$d" "$e" "$f"
          done
        done
      done
    done
  done
done

And if that's too slow in bash, consider using awk or perl or C.

[toc] | [standalone]


Back to top | Article view | gnu.bash.bug


csiph-web