Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

IINM my system is failing when bashing

for i in {0..10000000}; #   Seven zeroes.
done #   `bash` exited and its `tmux` pane/window was closed.


for i in $(seq 0 10000000); #   Seven zeroes.
done #   `bash` exited and its `tmux` pane/window was closed.

but not when

for i in {0..1000000}; #   Six zeroes.
done #   Finished correctly.

Can you please briefly explain the internals of this behavior and prompt a workaround for getting the task done?

share|improve this question
For you my all loved XY friends, a big file with CRLFs only is what I am actually trying to get. – uprego Aug 27 '14 at 12:28
Testing nl with lines alot, tabs and XY pow are what I got. – uprego Aug 27 '14 at 12:48
up vote 9 down vote accepted

for i in {0..1000000} and for i in $(seq 1000000) both build up a big list and then loop over it. That's inefficient and uses a lot of memory.


for ((i = 0; i<= 1000000; i++))

instead. Or POSIXly:

i=0; while [ "$i" -le 1000000 ]; do
  i=$(($i + 1))


seq 1000000 | xargs...

To get a file full of CRLFs:

yes $'\r' | head -n 1000000 >  file

Generally, loops should be avoided when possible in shells.

share|improve this answer
there's also the old /dev/zero/ thing... like tr \\0 \\r </dev/zero | tee - - - | dd or head or whatever... It might be better to mount a tmpfs of that size and fill it then cp to a file. Maybe not... – mikeserv Aug 27 '14 at 12:35
@mikeserv, yes Pourquoi faire simple quand on peut faire compliqué ? like they say in France. – Stéphane Chazelas Aug 27 '14 at 12:38
dang man. you really are a funny guy sometimes. now I have to translate that... ahh. the double entendre. that's probably French too. and, yeah, I dunno why I do. but I do. – mikeserv Aug 27 '14 at 12:39
Telling you to work a pearl for it. – uprego Aug 27 '14 at 12:41

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.