使用 Linux cowsay 命令制作丰富多彩的节日问候
cowsay

> 
> 用这个有趣的 Linux 命令行工具来庆祝节日吧。
> 
> 
> 


![](/data/attachment/album/202111/12/101540nq1nut3gzkzz1qus.jpg "Pumpkins painted for Day of the Dead")


你可能听说过这样一个小程序：它能接受输入信息（比如你通过键盘输入的消息），并输出一张引用了输入消息的牛的图像。这个小程序被称为 `cowsay`，之前我们已经 [介绍](https://opensource.com/article/18/12/linux-toy-cowsay) 过了。


所以，为了搞点有趣的事，我想用它来庆祝 <ruby> 亡灵节 <rt>  Día de los Muertos </rt></ruby>（LCTT 译注：墨西哥传统的鬼节，著名动画电影《<ruby> 寻梦环游记 <rt>  Coco </rt></ruby>》即以此为背景）。


除了牛之外，其实还有一些其他的可用图像。当安装 `cowsay` 时，程序会自动安装其他几个图像，并存储在 `/user/share/cowsay` 目录中。你可以用 `-l` 参数来获取图像列表。



```
$ sudo dnf install cowsay
$ cowsay -l

```

实际上还有很多与 `cowsay` 或类似程序相关的开发活动。你可以创建自己的图像文件，也可以下载其他人制作的图像。例如，GitHub 上就有 [Charc0al 的 cowsay 文件转换器](https://charc0al.github.io/cowsay-files/converter/)。你可以用这一工具将自己的图片转换为 `cowsay` 所需的特殊 ASCII 格式文件。根据 Linux 或 FreeBSD 终端设置不同，你可能会启用颜色支持，而 `cowsay` 也可以显示彩色图像。Charc0al 的转换器也提供了许多现成的颜色文件。


我选择了“<ruby> 甲壳虫汁 <rt>  Beetlejuice </rt></ruby>”（LCTT 译注：同名美国奇幻喜剧电影中的主角大法师）文件来开展我的“庆祝活动”。首先，我将 [beetlejuice.cow](https://raw.githubusercontent.com/charc0al/cowsay-files/master/cows/beetlejuice.cow) 文件保存到了 `/usr/share/cowsay` 目录。这个目录权限属于 root 用户，你可以先将该文件保存到家目录，然后再复制过去。此外我们还需要将该文件的读取权限赋予所有用户。



```
$ sudo cp beetlejuice.cow /usr/share/cowsay
$ sudo chmod o+r /usr/share/cowsay/beetlejuice.cow

```

关注一下图像是如何生成的（过程很有趣）。首先将各种 ASCII 颜色控制代码设置为变量，然后用这些变量，以传统的 ASCII 艺术风格绘制图像。生成的图像几乎是全身的，并且在不滚动屏幕的情况下，不适配我的终端的高度，所以我编辑了一下该文件，删除了最后 15 行以降低高度。


这个图像也可以被 `cowsay` 程序检测到，并展示在列表中。



```
$ cowsay -l
Cow files in /usr/share/cowsay:
beavis.zen beetlejuice blowfish bud-frogs bunny cheese cower default dragon
...

```

现在，只要运行程序，并使用 `-f` 选项指定该图像就可以了。别忘了提供要输出的信息。



```
$ cowsay -f beetlejuice "Happy Day of the Dead!"

```

![ASCII display of Beetlejuice via cowsay](/data/attachment/album/202111/12/101550f36433zeeaq757qe.png)


*“甲壳虫汁”祝你亡灵节快乐 (CC BY-SA 4.0)*


`cowsay` 是 Linux 中一个有趣的搞怪小玩意。发挥你的创意，探索一下 `cowsay` 以及 ASCII 的艺术吧。




---


via: <https://opensource.com/article/21/11/linux-cowsay>


作者：[Alan Formy-Duval](https://opensource.com/users/alanfdoss) 选题：[lujun9972](https://github.com/lujun9972) 译者：[unigeorge](https://github.com/unigeorge) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
You may have heard of a small program that takes input, such as a message that you type, and outputs a picture of a cow quoting your message. It is called **cowsay**. It has been written about before here on [Opensource.com](https://opensource.com/article/18/12/linux-toy-cowsay).

So, to have a little fun with it, I thought I'd use it to celebrate Día de los Muertos (Day of the Dead).

In addition to a cow, there are other images available. When you install `cowsay `

it includes several other images, which the install stores in `/user/share/cowsay`

. You can use the `-l`

argument to get a list.

```
$ sudo dnf install cowsay
$ cowsay -l
```


There's actually quite a bit of development activity related to `cowsay`

and similar programs. It is possible to create your own image files or download images others have made. For instance, [Charc0al's cowsay file converter](https://charc0al.github.io/cowsay-files/converter/) is located on GitHub. You can use this tool to convert your own pictures to the special ASCII format file required by `cowsay`

. Depending on your Linux or FreeBSD terminal settings, you may have color support enabled. The `cowsay`

utility can display color images, as well. Charc0al's converter provides many ready-to-go color files.

I chose to use the Beetlejuice file for my celebration. First, I saved the [beetlejuice.cow](https://raw.githubusercontent.com/charc0al/cowsay-files/master/cows/beetlejuice.cow) file to `/usr/share/cowsay`

. This directory is owned by root, so you may have to save the file to your home directory first and then copy it. I also needed to give all users read access.

```
$ sudo cp beetlejuice.cow /usr/share/cowsay
$ sudo chmod o+r /usr/share/cowsay/beetlejuice.cow
```


It is interesting to notice how the image is generated. The top sets various ASCII color control codes to variables. These variables are then used to draw the image in the traditional ASCII art style. The image is almost full-body and did not fit my terminal height without scrolling off the screen, so I edited the file and removed the last 15 lines to shorten it.

The image is also detected by the `cowsay`

program and appears in the list.

```
$ cowsay -l
Cow files in /usr/share/cowsay:
beavis.zen beetlejuice blowfish bud-frogs bunny cheese cower default dragon
...
```


Now, simply run the program and specify the image using the `-f`

option. Don't forget to provide a message.

`$ cowsay -f beetlejuice "Happy Day of the Dead!"`



![ASCII display of Beetlejuice via cowsay](https://opensource.com/sites/default/files/cowsay_beetlejuice.png)

Beetlejuice says Happy Day of the Dead (CC BY-SA 4.0)

The `cowsay`

command is just another way to have some command-line fun with your Linux computer. Experiment with `cowsay`

and ASCII art—get creative.

## 2 Comments