0

I made a basic bash script piping fortune and cowsay to make a wise cow, and titled it appropriately as wisecow Is there a way I can enable the flags associated with cowsay so that I can input

wisecow -s

and get the stoner cow, or -b for the borg cow, or what have you?

Currently when I do

wisecow -d

or whatever, the cow looks the same as if I hadn't used the flag

the code lol:

#!/bin/bash
fortune | cowsay
4
  • You can use the bash builtin command getopts so that your script can process its arguments and you can pass them on to whichever command. Search here and Stack Overflow for getopts, there are loads of examples. Commented Oct 25, 2019 at 2:04
  • thank you. would I just put that in a new line on the script?
    – gwyns
    Commented Oct 25, 2019 at 2:11
  • Ahhh, thank you. I forgot to put it in when I rewrote the post, I'll pop it in. That fixed it, thank you very much @steeldriver
    – gwyns
    Commented Oct 25, 2019 at 3:44

1 Answer 1

2

You give some option to your script, but you never pass it on to cowsay.

To do that, use

fortune | cowsay "$@"

in your script. The "$@" will expand to the list of command line arguments that your script was given, for example the option -d, if that was what you invoked your script with.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .