zoukankan      html  css  js  c++  java
  • 输出彩色Shell

    Task: Add colors to the prompt

    To add colors to the shell prompt use the following export command syntax:
    '\e[x;ym $PS1 \e[m'

    Where,

    \e[ Start color schemex;y Color pair to use (x;y)$PS1 is your shell prompt\e[m Stop color scheme

    To set a red color prompt, type the command:

    $ export PS1="\e[0;31m[\u@\h \W]\$ \e[m "

    List of Color codeColorCodeBlack0;30Blue0;34Green0;32Cyan0;36Red0;31Purple0;35Brown0;33Blue0;34Green0;32Cyan0;36Red0;31Purple0;35Brown0;33

    Replace digit 0 with 1 to get light color version.

    前景色 30 (黑色)、31 (红色)、32 (绿色)、33 (黄色)、34 (蓝色)、35 ( 紫红色)、36 (青色)、37 (白色)

    背景色 40 (黑色)、41 (红色)、42 (绿色)、43 (黄色)、44 (蓝色)、45 ( 紫红色)、46 (青色)、47 (白色)

    属性数值:0、1、 22、4、24、25、7、27,分别定义颜色、黑体、非黑体、下画线、非下画线、闪烁、非闪烁、翻转、非翻转。

    格式可以写成:"\033[0;37;44m"

    Create tem scripts:

    vim color.sh 

    #!/bin/bash

    red='\e[0;31m'

    RED='\e[1;31m'

    green='\e[0;32m'

    GREEN='\e[1;32m'

    blue='\e[0;34m'

    BLUE='\e[1;34m'

    cyan='\e[0;36m'

    CYAN='\e[1;36m'

    NC='\e[0m' 

    echo -e "${green} Please input a number:${NC}(time format ${RED} s|m|h|d${NC})"

    运行脚本输出效果是:Please input a number:(time format  s|m|h|d)
    大家可以试试,这片文章七拼八凑起来的!

  • 相关阅读:
    发送邮件程序
    T-SQL存储过程、游标
    GPS经纬度换算成XY坐标
    开博了
    你应该知道的 50 个 Python 单行代码
    想提升java知识的同学请进
    adb工具包使用方法
    红米note3刷安卓原生
    hadoop 使用和javaAPI
    django学习——url的name
  • 原文地址:https://www.cnblogs.com/storymedia/p/4436136.html
Copyright © 2011-2022 走看看