-2
fortune -a | cowsay -f daemon | lolcat  
fortune -a | cowsay -f beavis.zen | lolcat

I want to combine the above 2 commands into one and to randomly choose the cowsay options.

Barmar
  • 669,327
  • 51
  • 454
  • 560
  • Put the arguments in an array, then see [how to select a random item from an array](https://stackoverflow.com/questions/2388488/how-to-select-a-random-item-from-an-array-in-shell) – Barmar May 25 '22 at 14:22
  • 1
    `fortune -a | cowsay -f $( test $(( RANDOM % 2 )) -eq 0 && echo daemon || echo beavis.zen ) | lolcat`. But the array is a better approach. – William Pursell May 25 '22 at 14:26
  • thanks @William Pursell your code worked! I tried using array and seems to work `fortune -a | cowsay -f $( arr[0]="daemon"; arr[1]="beavis.zen"; rand=$[$RANDOM % ${#arr[@]}]; echo ${arr[$rand]} ) | lolcat` – Idowu Ambiguity May 25 '22 at 16:09
  • Shortest POSIX-sh one-liner, using obsolete arithmetic expression syntax: `read a – Léa Gris May 25 '22 at 17:46

0 Answers0