From dcfc977fc0d3d00454bfbe5e744aed6009b2a899 Mon Sep 17 00:00:00 2001 From: Salt Date: Fri, 21 Dec 2018 15:26:17 -0600 Subject: [PATCH] cowsayeternal: Use a temporary file to circumvent argument size restrictions --- cowsayeternal | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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