Bash – Fix Echo Write Error: Interrupted System Call

bash

I want to generate a sorted list with all 8-digit numbers — from 00000000 to 99999999.
I typed in the shell:

f() {
 while IFS="" read -r line; do
   for i in {0..9}; do 
       echo "$line$i";
   done;
 done
}

echo | f | f | f | f | f | f | f | f | tee result.txt | wc -l

response is

bash: echo: write error: Interrupted system call
bash: echo: write error: Interrupted system call
bash: echo: write error: Interrupted system call
99998890

Why have I got these three errors and malformed result.txt ?

I use

GNU bash, version 4.4.12(1)-release (x86_64-pc-linux-gnu)

Debian GNU/Linux 9.6 (stretch)

Linux kernel: 4.19.0 #2 SMP Thu Nov 1 15:31:34 EET 2018 x86_64 GNU/Linux

Best Answer

The specific write error: Interrupted system call error is generated when the console window size is changed while the script is being executed.

Doing a:

 trap '' SIGWINCH

will avoid it.

Note that a

 seq 99999999 >result.txt; wc -l <result.txt

Will be both faster and will avoid the SIGWINCH issue.

Related Question