stdout/stderr output not in correct order in logs

Example:

+ ls -al rawpy/.dylibs
total 3720
drwxr-xr-x 6 runner staff 192 Sep 23 21:05 .
drwxr-xr-x 7 runner staff 224 Sep 23 21:05 ..
-rw-r--r-- 1 runner staff 270728 Jan 1 1980 libjasper.5.0.0.dylib
+ echo 'Dumping LC_VERSION_MIN_MACOSX'
.github/scripts/build-macos.sh: line 75: syntax error near unexpected token `echo'
-rw-r--r-- 1 runner staff 211376 Jan 1 1980 libjpeg.9.dylib
-r--r--r-- 1 runner staff 298312 Jan 1 1980 liblcms2.2.dylib
-rwxr-xr-x 1 runner staff 1115196 Jan 1 1980 libraw_r.19.0.0.dylib
Dumping LC_VERSION_MIN_MACOSX

The output of the ls command is interleaved with stderr, in this case from the shell script by using set -x. I assume it is to do with differences in buffering between stdout/stderr. Both streams should probably be line buffered to avoid this.

2 Likes