输出彩色Shell
2011-02-21 23:12
190 查看
Task: Add colors to the promptTo 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 schemeTo set a red color prompt, type the command:
$ export PS1="\e[0;31m[\u@\h \W]\$ \e[m "
List of Color code[b]ColorCodeBlack0;30Blue0;34Green0;32Cyan0;36Red0;31Purple0;35Brown0;33Blue0;34Green0;32Cyan0;36Red0;31Purple0;35Brown0;33
Replace digit 0 with 1 to get light color version.
[/b]
前景色 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)
大家可以试试,这片文章七拼八凑起来的!
'\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 schemeTo set a red color prompt, type the command:
$ export PS1="\e[0;31m[\u@\h \W]\$ \e[m "
List of Color code[b]ColorCodeBlack0;30Blue0;34Green0;32Cyan0;36Red0;31Purple0;35Brown0;33Blue0;34Green0;32Cyan0;36Red0;31Purple0;35Brown0;33
Replace digit 0 with 1 to get light color version.
[/b]
前景色 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)
大家可以试试,这片文章七拼八凑起来的!
相关文章推荐
- Shell输出彩色字符串
- shell模板-跨目录执行,彩色输出,临时文件,行遍历文件
- Python/Perl/Shell 输出彩色字体
- 使用shell输出彩色日志简单实现
- Python/Perl/Shell 输出彩色字体
- linux终端中输出彩色字体(C/SHELL)
- shell输出彩色的字符串
- Shell中打印彩色输出
- C && Shell利用转义字符输出彩色字体
- shell-每日一点(打印彩色输出)
- linux终端中输出彩色字体(C/SHELL)
- shell在终端输出彩色文本
- linux终端中输出彩色字体(C/SHELL)
- gtest 的彩色信息输出 + boost.test 的内存泄漏检测及定位
- Python终端如何输出彩色字体
- 8.1 shell介绍 8.2 命令历史 8.3 命令补全和别名 8.4 通配符 8.5 输入输出重
- 十六、shell中的输入与输出
- SHELL 数组分片输出
- NASM汇编实现彩色输出
- Linux程序中执行shell(程序、脚本)并获得输出结果