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


Groups > gnu.bash.bug > #14219

Re: Sequence Brace Expansion Crash

Path csiph.com!goblin1!goblin.stu.neva.ru!usenet.stanford.edu!not-for-mail
From Greg Wooledge <wooledg@eeg.ccf.org>
Newsgroups gnu.bash.bug
Subject Re: Sequence Brace Expansion Crash
Date Mon, 4 Jun 2018 09:02:33 -0400
Lines 29
Approved bug-bash@gnu.org
Message-ID <mailman.1111.1528117360.1292.bug-bash@gnu.org> (permalink)
References <CAGbX=_V_2OvOA-5DJ6iPCvCoZy9W8j1Y4K+LnCT=Cfh=v9H3eQ@mail.gmail.com>
NNTP-Posting-Host lists.gnu.org
Mime-Version 1.0
Content-Type text/plain; charset=us-ascii
X-Trace usenet.stanford.edu 1528117361 18219 208.118.235.17 (4 Jun 2018 13:02:41 GMT)
X-Complaints-To action@cs.stanford.edu
To bug-bash@gnu.org
Envelope-to bug-bash@gnu.org
Mail-Followup-To bug-bash@gnu.org
Content-Disposition inline
In-Reply-To <CAGbX=_V_2OvOA-5DJ6iPCvCoZy9W8j1Y4K+LnCT=Cfh=v9H3eQ@mail.gmail.com>
User-Agent NeoMutt/20170113 (1.7.2)
X-detected-operating-system by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy]
X-Received-From 139.137.100.1
X-BeenThere bug-bash@gnu.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org>
List-Unsubscribe <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe>
List-Archive <http://lists.gnu.org/archive/html/bug-bash/>
List-Post <mailto:bug-bash@gnu.org>
List-Help <mailto:bug-bash-request@gnu.org?subject=help>
List-Subscribe <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe>
Xref csiph.com gnu.bash.bug:14219

Show key headers only | View raw


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.

Back to gnu.bash.bug | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web