---
title: "为输出添加颜色"
author: "jedy"
date: "2007-11-10T16:26:00Z"
tags: []
slug: "untitled"
draft: false
lastmod: "2007-11-10T16:26:00Z"
id: 304666
url: "https://jedy.iteye.com/blog/304666"
---

```
$str = "TAKE CARE";
if(-t STDOUT){
  print "\e[1;31m$str\e[0m\n";
} else {
  print "$str\n";
}
```

-t 是判断输出是不是tty，如果是的则输出颜色信息，如果不是，比如在STDOUT被重定向到文件时则不加颜色信息。