Created
September 26, 2014 12:52
-
-
Save anonymous/2e5c9de580f330bca1a6 to your computer and use it in GitHub Desktop.
Sample program for https://unix.stackexchange.com/questions/157689/how-to-capture-ordered-stdout-stderr-and-add-timestamp-prefixes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
function generator() { | |
local I=1 | |
while [ $I -le 50 ]; do | |
echo "Line $I" | |
let I+=1 | |
done | |
} | |
function alternator() { | |
local LN=0 | |
while read -r LINE; do | |
test $((LN % 2)) -eq 0 && echo "$LINE" || echo "$LINE" 1>&2 | |
let LN+=1 | |
done | |
} | |
generator | alternator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment