Sunday, April 28, 2024
14
rated 0 times [  14] [ 0]  / answers: 1 / hits: 53655  / 3 Years ago, fri, october 15, 2021, 3:35:32

I have installed cowsay and fortune. I want to set my own talks or texts in cowsay. But I can't configure it out. When I open terminal there is nothing from cowsay. I want to show cowsay when I start terminal.



But this works:



hash@ssl50:~$ cowsay -f tux "Carry on"

< carry on >
----------


.--.
|o_o |
|:_/ |
//
(| | )
/'_ _/`
___)=(___/

More From » command-line

 Answers
6

Well, in Linux Mint there is a fun thing you could do: write a script to select a cow and display a message from fortune. I'll get to it later. Once you have the script, all you have to do is to execute it. As suggested before, edit your ~/.bashrc file and add at the end a line containing the path to your script. For example, if you have the script in your home folder and the script's filename is "cowscript", then you could add the following line at the end of your ~/.bashrc file:



$HOME/cowscript


Now, the script used in Linux Mint 9 is the following:



#!/bin/bash
RANGE=4

number=$RANDOM
let "number %= $RANGE"
case $number in
0)
cow="small"
;;
1)
cow="tux"
;;
2)
cow="koala"
;;
3)
cow="moose"
;;
esac

RANGE=2
number=$RANDOM
let "number %= $RANGE"
case $number in
0)
command="/usr/games/cowsay"
;;
1)
command="/usr/games/cowthink"
;;
esac
/usr/games/fortune | $command -f $cow


Basically, it will display a random cow (either small, tux, koala, or moose) and the message will be taken from fortune. Also, this script will execute wither cowsay or cowthink, the only difference being that cowthink will display a thinking cow instead of a talking cow.



Now, the fun thing is that you can modify the script to show more cows or to show different cows. To do that, you first need to know what cows you have installed. In a terminal, run:



cowsay -l


You can use any of those cows. All you have to do is to edit the script: if you want to add a new cow, just copy the lines containing "cow" (plus the number and semi-colons) and paste them before the line that says "esac". Then, change the number and name of the cow, so for instance, if you want to add a cow called "udder", all you have to do is to add these lines before the first "esac":



4)
cow="udder"
;;


Important: the second line of the file, "RANGE=4", must be changed also. If you add one cow, then instead of 4 use 5, also if you delete one cow, then you must use 3, and so on. Also note that the numbers that you see must be in the range from 0 to RANGE - 1. That's why RANGE is 4 and the numbers are 0, 1, 2, and 3.



You could also create your own cows, although that might take a bit more of work. All you have to do is to get any ASCII art you like and edit it, but it is a bit tricky. You can see how it's done here: http://lmpeiris.wordpress.com/2011/01/17/cowsayhow-to-make-a-cow-talk-on-terminal-startup/ However, consider that any @ and symbols need to be backslashed, that is, you must put before that symbol this other symbol: . This might be the case for #, too (but not always). If your ASCII Art contains #, you could backslash it too, but sometimes it would be enough with just one of them... I'm not sure how to explain it, sorry. I guess you will have to try to see if it works. Also, make sure that the file you edit has the extension ".cow"



Finally, once you have your own cows, you can either add them to the default location (you probably will need to be superuser for that) at /usr/share/cowsay/cows, or you could add to your ~/.bashrc file this lines:



export COWPATH="/usr/share/cowsay/cows"
# set COWPATH so it includes user's cows
if [ -d "$HOME/cowfiles" ] ; then
COWPATH="$COWPATH:$HOME/cowfiles"
fi


Be sure to add those lines before you call your "cowscript". This also assumes that you have a folder called "cowfiles" on your home folder. Change the path if you want so it points to the folder where you have your cowfiles.


[#38248] Sunday, October 17, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
onbean

Total Points: 29
Total Questions: 102
Total Answers: 115

Location: Benin
Member since Fri, Mar 24, 2023
1 Year ago
onbean questions
Fri, Mar 18, 22, 19:49, 2 Years ago
Tue, Dec 6, 22, 11:51, 1 Year ago
Mon, Jun 7, 21, 17:21, 3 Years ago
Mon, Jan 16, 23, 04:48, 1 Year ago
Mon, Oct 17, 22, 14:51, 2 Years ago
;