Shell 设置控制台输出字段格式

实现代码

#!/bin/bash

# ANSI Color -- Use these variables to make output in different colors
# and formats. Color names that end with 'f' are foreground (text) colors,
# and those ending with 'b' are background colors.
initializeANSI()
{
  esc="\033" # if this doesn't work, enter an ESC directly
  blackf="${esc}[30m";  redf="${esc}[31m";  greenf="${esc}[32m";
  yellowf="${esc}[33m";  bluef="${esc}[34m";  purplef="${esc}[35m";
  cyanf="${esc}[36m";  whitef="${esc}[37m";

  blackb="${esc}[40m";  redb="${esc}[41m";  greenb="${esc}[42m";
  yellowb="${esc}[43m"  blueb="${esc}[44m";  purpleb="${esc}[45m";
  cyanb="${esc}[46m";  whiteb="${esc}[47m";

  boldon="${esc}[1m";boldoff="${esc}[22m";
  italicson="${esc}[3m";italicsoff="${esc}[23m";
  ulon="${esc}[4m";uloff="${esc}[24m"
  invon="${esc}[7m";   invoff="${esc}[27m";

  reset="${esc}[0m"
}


initializeANSI
echo "${yellowf}${redb}This is a phrase font-color is yellow and background-color is red${reset}"
echo "${boldon}This is bold${reset} ${ulon}This is underline${reset}"
echo "${italicson}This is italics${italicsoff} and this is not"

控制台输出:


WX20180224-111025@2x.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 181,034评论 25赞 708
  • 发现 关注 消息 iOS 第三方库、插件、知名博客总结 作者大灰狼的小绵羊哥哥关注 2017.06.26 09:4...
    肇东周阅读 17,157评论 4赞 61
  • 咚了咚咚…… 咚了咚咚…… 手机的短信铃声响了。 前两天三叔打过来电话:喂?大侄干啥呢,最近怎么样? “还…还那...
    我真的不是孔祥东阅读 932评论 3赞 6
  • 黄赌毒
    苏浩亮阅读 296评论 1赞 0
  • 文/冬日暖扬 第十一回 烧烤 以前和奶奶住在山上的时候,晓渔虽然也会和附近村子的小孩子们玩儿,但象现在同这么多还一...
    冬日暖扬阅读 418评论 8赞 26

友情链接更多精彩内容