linux - Bash: How to build a recursive cowsay -


here's linux command (you might need cowsay application.

cowsay 'moo' 

here's command:

cowsay 'moo' | cowsay -n 

the result pretty entertaining:

 ______________________________ /  _____                       \ | < moo >                      | |  -----                       | |         \   ^__^             | |          \  (oo)\_______     | |             (__)\       )\/\ | |                 ||----w |    | \                 ||     ||    /  ------------------------------         \   ^__^          \  (oo)\_______             (__)\       )\/\                 ||----w |                 ||     || 

now, of course, it's pretty fun repeat piped command n times. looks little this:

 cowsay 'moo' | cowsay -n | cowsay -n | cowsay -n | cowsay -n | cowsay -n | cowsay -n | cowsay -n | cowsay -n | cowsay -n | cowsay -n | cowsay -n 

cows nested inside cows saying things

but i'm thinking there must neater way of achieving this. let's want 500 cows saying each other, or 1,000, or 1,000,000. surely don't have keep finger on paste button?

here's question; there way in bash (command or script) recursively pass output of command given number of times?

cowsayn() {     local n=$1     shift     if ((n>1));         cowsay -n | cowsayn $((n-1))     else         cowsay -n     fi } echo 'moo' | cowsayn 500 

Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -