diff --git a/cowsayeternal b/cowsayeternal index 8a62974..edada1c 100755 --- a/cowsayeternal +++ b/cowsayeternal @@ -1,10 +1,16 @@ #!/bin/bash -cowsaid="$(cowsay "E T E R N A L")" +cowsaidfile="$(mktemp)" +cowsay "E T E R N A L" > "$cowsaidfile" trap_exit() { - printf "%s" "$cowsaid" + cat "$cowsaidfile" + rm "$cowsaidfile" } trap trap_exit EXIT while true; do - cowsaid="$(cowsay -n <<< "$cowsaid")" - printf "%s characters of cowsay; hit Ctrl+C to dump them\\n" "$(wc -c <<< "$cowsaid")" + # 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" + printf "%s bytes of cowsay; hit Ctrl+C to dump them\\n" \ + "$(stat --printf="%s" "$cowsaidfile")" done