cowsayeternal: Use a temporary file to circumvent argument size restrictions

This commit is contained in:
Salt 2018-12-21 15:26:17 -06:00
parent 4559167e88
commit dcfc977fc0

View File

@ -1,10 +1,16 @@
#!/bin/bash #!/bin/bash
cowsaid="$(cowsay "E T E R N A L")" cowsaidfile="$(mktemp)"
cowsay "E T E R N A L" > "$cowsaidfile"
trap_exit() { trap_exit() {
printf "%s" "$cowsaid" cat "$cowsaidfile"
rm "$cowsaidfile"
} }
trap trap_exit EXIT trap trap_exit EXIT
while true; do while true; do
cowsaid="$(cowsay -n <<< "$cowsaid")" # Shut up shellcheck; that's the whole point. cowsay does a full read
printf "%s characters of cowsay; hit Ctrl+C to dump them\\n" "$(wc -c <<< "$cowsaid")" # 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 done