对echo做过一个简单包装。。。

第一个GitHub上的作业。。。

只支持ascii颜色。。。

cecho,直接把readme拷贝过来了。

cecho

Colorful echo for unix-like shell ( ascii color only )

Overview

A light, self-adapting wrapper of echo, with color flags of foreground, background and action ( highlight, underline, blink ... ) . With it, you can easily colorize your output of command and shell script.

Tested in zsh and bash.

Screenshot

Active

Inactive

Install

Before use cecho, simply source it in your .zshrc, or any shell script wanted to colorize like this:

source /path/to/cecho.sh

Usage

Support multi-string in one command:

cecho -color1 message1 [ -color2 message2 ... ] [ -done ]

Support setting foreground, background and action

cecho -fg_color -bg_color -action message [...] [ -done ]

All flags have two formats, short for convenience, long for readability.

The short formats is easily memorized, which are nearly just the heads the long formats.

Foreground color flag

short

long

-r

-red

-g

-green

-y

-yellow

-b

-blue

-p

-purple

-c

-cyan

-w

-white

-gr

-gray

-bk

-black

Background color flag

short

long

-br

-b_red

-bg

-b_green

-by

-b_yellow

-bb

-b_blue

-bp

-b_purple

-bc

-b_cyan

-bw

-b_white

-bgr

-b_gray

-bbk

-b_black

Action flag

short

long

-d

-done

-hl

-highlight

-ul

-underline

-re

-reverse

-bl

-blink

-iv

-invisible

Escaped character

short

long

-B

-blank

-t

-tab

-n

-newline

Functional

short

long

-h

-help,--help

Example

set fg to red:

cecho -r "hello world ! "

or

cecho -red "hello world ! "

or

cecho -r hello -B world -B !

blank & tab & newline

cecho -r -t hello -B world -n !

set fg to red, bg to yellow, action to highlight and underline:

cecho -r -by -hl "hello world ! "

set [ red, yellow, highlight & underline ] for "hello", [ cyan, red, reverse ] for "world", [ green, black, blink ] for "!" :

cecho -r -by -hl -ul hello -d -B -c -br -re world -d -B -g -bl !

More examples in help file triggered with this command

cecho -h

Useful Variables

CECHO_IS_IMPORTED

Once you have sourced cecho, CECHO_IS_IMPORTED=1 will be defined.

That meams you can check this var CECHO_IS_IMPORTED to confirm if in a no_cecho env or not:

CECHO_IS_INACTIVE

When you use cecho but want it inactive temply, set CECHO_IS_INACTIVE=1 before calling cecho.

Note: color and action can be disable by CECHO_IS_INACTIVE, but we keep return, blank and tab active, as you wish.

Sence

1 - I want my script outputs to file/pipe without color_ctrl chars

Needn't do any change, cecho can self-adapting this: colorful for stdout, non-colorful for file/pipe.

2 - My script maybe runs in both "no-cecho env" and "cecho env"

Unfortunately, you have to write your script like this:

if [ -z "$CECHO_IS_IMPORTED" ]

then

echo hello world

else

cecho -r -bg -hl hello -B world

fi

Or shortly:

[ -z "$CECHO_IS_IMPORTED" ] && echo "hello world" || cecho -r -bg -hl hello -B world

3 - My script uses cecho but I want it disabled temply

CECHO_IS_INACTIVE=1

cecho -r -bg -hl hello world #

CECHO_IS_INACTIVE=

cecho -r -bg -hl hello world #

Advanced

Action flag -d ( same as -done ) will turn off all settings ( fg, bg and action ), Thus, in single command, you have to set flags again to make it work well once there are other strings after -d.

Some special characters ( with centain format ) don't work well, such as cecho "!". It's due to echo... use cecho '!' or cecho ! instead.

It's not necessary use -d at the begin/end of commands, cecho do it automatically.

Actions can overlaied.

What's more

Another C version project is coprintf.

Thanks

Thanks to https://github.com/jonhiggs/cecho, when I completed cecho script and try uploading it to github I found this -- with same name and almost same functions ... and then, I got the way to build table in README.md from there.

linux shell 输出红色,Bash Shell怎么打印各种颜色相关推荐

  1. Linux编程 3 (初识bash shell与man查看手册)

    一.初识bash shell 1.1 启动 shell   GNU bash shell 能提供对Linux系统的交互式访问.通常是在用户登录终端时启动,登录时系统启动shell依赖于用户账户的配置. ...

  2. linux shell 一行 for,BASH shell脚本回显到同一行输出

    我有一个简单的BASH shell脚本,它检查curl命令的HTTP响应代码. 逻辑很好,但我坚持"简单地"打印出"输出". 我正在使用GNU bash,版本3 ...

  3. linux shell 函数库,bash shell 函数库

    bash shell 函数库ash由自由软件基金会,Inc.版权所有(C) 1989-2011. 语法 bash [options] [file] 描述 Bash是一种与sh兼容的命令语言解释器,它执 ...

  4. linux shell 数组对比,bash shell之数组使用(牛逼篇)

    这次写脚本时用到了bash shell数组,当初做法是配置文件里面写成数组形式A=(element1 element2 element3 .... element4),然后一个脚本读取这个配置文件,于 ...

  5. linux系统下的bash shell指令有哪些?对bash命令的汇总和小结

    一.参考来源 Windows系统的cmd命令哪些?具体怎么用?cmd命令汇总,dos命令小结?和linux命令的对比? 下面这个网站,强烈推荐,一旦遇到自己不懂的linux命令,直接去这个开源站检索即 ...

  6. linux shell 执行目录,bash shell脚本执行的几种方法

    bash shell 脚本执行的方法有多种,本文作一个总结,供大家学习参考. 假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一: ...

  7. Linux学习笔记四--Bash Shell

    查看某一命令是否是来自于外部命令还是内置于bash中:type [-tpa] name      也可用来查找命令,如:type -p touch 有/bin/touch:type -p vbird无 ...

  8. Linux中srch出现bash,Shell练习题(3)

    (1)查找字母数小于6的单词 用shell打印下面这句话中字母数小于6的单词. Bash also interprets a number of multi-character options. #! ...

  9. linux shell declare -a,Bash Shell之declare定义变量

    实验环境 ~]# cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core) 命令说明 declare 与 typeset 命令都是bas ...

最新文章

  1. 面试必备的 23 个JVM 面试真题!
  2. 1.5 Activity08 RadioButton
  3. 【2012百度之星/资格赛】E:C++ 与Java
  4. 联想m100显示耗材_RTX3070显卡搭档高性能显示器,畅玩精美游戏大作!
  5. css hack *html,HTML_CSS Hack整理,CSS Hack是在标准CSS没办法兼容 - phpStudy
  6. 查理.芒格,谈投资的秘密
  7. 自学Java要不要背熟语法_JAVASE经典面试问题(必须熟背),你Get到了吗?
  8. 拥抱SQLAlchemy 之二 拉拉手,我请你去看电影~
  9. Noip 模拟练习9
  10. 破解Root密码_wuli大世界_新浪博客
  11. c语言多个自我介绍编码,代码自我介绍.doc
  12. Aurora8B10B IP使用 -01- 简介与端口描述
  13. 某某文学网站小说爬虫
  14. CIA-SSD: Confident IoU-Aware Single-Stage Object Detector From Point Cloud阅读
  15. python3.6安装步骤-Python 3.6.6安装教程(附安装包) | 我爱分享网
  16. SoftLayer VPS好吗?SoftLayer VPS机房优势有哪些
  17. oracle oats 工具讲解,Oracle 表空间基本操作
  18. 深度科普:拆解让机器人走路更「丝滑」的TEB算法
  19. 【红蓝对抗】边界突破-思维导图
  20. 关于架构、架构师和技术团队的一些事情

热门文章

  1. 归纳编程语言的语法grammer
  2. c语言简单的字符串处理
  3. cmd html 查找汉子字,cmd搜索字符串加换行 在cmd(命令提示符)中怎样换行
  4. win2019离线安装.NET Framework 3.5的方法
  5. canvas绘制图片
  6. 知识图谱:如何推动金融更智能?
  7. 如何阻止电脑下载安装垃圾软件?阻止电脑下载垃圾软件方法
  8. 医疗AI机器人Woebot获800万美元融资,帮助人们应对抑郁等精神疾病
  9. 计算机操作不当有什么危害,驾考过程出现考官操作不当或电脑误判谁来承担责任...
  10. 自学计算机基础知识本科,没有专业基础自学考试计算机本科会很吃力吗?