2018-12-21 13:46:10 -06:00
|
|
|
#!/bin/bash
|
2018-12-21 15:26:17 -06:00
|
|
|
cowsaidfile="$(mktemp)"
|
2018-12-31 13:59:48 -06:00
|
|
|
printf "Writing cows to temporary file \"%s\"\\n" \
|
|
|
|
"$cowsaidfile"
|
2018-12-21 15:26:17 -06:00
|
|
|
cowsay "E T E R N A L" > "$cowsaidfile"
|
2018-12-21 13:46:10 -06:00
|
|
|
trap_exit() {
|
2018-12-31 13:59:48 -06:00
|
|
|
printf "\\n"
|
2018-12-21 15:26:17 -06:00
|
|
|
cat "$cowsaidfile"
|
|
|
|
rm "$cowsaidfile"
|
2018-12-21 13:46:10 -06:00
|
|
|
}
|
|
|
|
trap trap_exit EXIT
|
2018-12-31 13:59:48 -06:00
|
|
|
iterations=1
|
2018-12-21 13:46:10 -06:00
|
|
|
while true; do
|
2018-12-21 15:26:17 -06:00
|
|
|
# Shut up shellcheck; that's the whole point. cowsay does a full read
|
|
|
|
# before it writes back to the file anyway.
|
|
|
|
# shellcheck disable=2094
|
|
|
|
cowsay -n < "$cowsaidfile" 1<> "$cowsaidfile"
|
2018-12-31 13:59:48 -06:00
|
|
|
iterations=$(( iterations + 1 ))
|
|
|
|
# This line will only ever grow larger, so we don't need to clear it
|
|
|
|
# before overwriting it.
|
|
|
|
printf "\\r%s iterations, %s bytes of cowsay; hit Ctrl+C to dump them" \
|
|
|
|
"$iterations" \
|
2018-12-21 15:26:17 -06:00
|
|
|
"$(stat --printf="%s" "$cowsaidfile")"
|
2018-12-21 13:46:10 -06:00
|
|
|
done
|