linux命令之echo

来源:百度文库 编辑:神马文学网 时间:2024/07/05 16:22:04
echo                                                                                    功能:显示文字。                                                                                  语 法:echo [-ne][字符串]或 echo [--help][--version]                                           参 数:-n 不要在最后自动换行                                                                      -e 若字符串中出现以下字符,则特别加以处理,而不会将它当成一般文字输出:                                                                                  \a 发出警告声;                                                                         \b 删除前一个字符;                                                                     \c 最后不加上换行符号;这个要放在要显示字符串的最后,如果不是放在字符串的最后,它后面的字符将不显示;                                                                 \f 换行但光标仍旧停留在原来的位置;                                                       \n 换行且光标移至行首;                                                                 \r 光标移至行首,但不换行;                比如:                #echo -e "aaaa\rbbb\rcc\rd"                #dcba              分析如下:             1:aaaa             2:bbba             3:ccba             4:dcba                                                                             \t 插入tab;                                                                            \v 与\f相同;                                                                           \\ 插入\字符;                                                                          \0nnn 插入nnn(八进制)所代表的ASCII字符;                                                            \xnn 插入nnn(十六进制)所代表的ASCII字符;    --help 显示帮助                                                                            --version 显示版本信息 使echo输出的字符串显示颜色echo -e '\E[COLOR1;COLOR;NUMBERmSome text goes here.\E[0m'
echo -e '\033[COLOR1;COLOR;NUMBERmSome text goes here.\033[0m'
例子如下:#echo -e '\E[40;31;1mhello,world\E[0m'hello,world#echo -e '\E[40;33;1mhello,world\E[0m'hello,world COLOR1      背景色 COLOR2      前景色
NUMBER     高亮为1,普通为0 色彩代码:色彩 前景色 背景色

黑        30          40

红        31          41

绿        32          42

黄        33         43

蓝       34          44

洋红   35         45

青       36         46

白       37         47   这个文件定义shell 中文件颜色的显示 /etc/DIR_COLORS    tty这个文件定义shell中文件颜色的显示 /etc/DIR-COLORS_xterm  pts/n 部分内容显示如下:# EIGHTBIT, followed by '1' for on, '0' for off. (8-bit output)
EIGHTBIT 1# Below are the color init strings for the basic file types. A color init
# string consists of one or more of the following numeric codes:
# Attribute codes:
# 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
# Text color codes:
# 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
# Background color codes:
# 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
NORMAL 00       # global default, although everything should be something.
FILE 00         # normal file
DIR 01;34       # directory
LINK 01;36      # symbolic link
FIFO 40;33      # pipe
SOCK 01;35      # socket
BLK 40;33;01    # block device driver
CHR 40;33;01    # character device driver
ORPHAN 01;05;37;41  # orphaned syminks
MISSING 01;05;37;41 # ... and the files they point to# This is for files with execute permission:
EXEC 01;32 # List any file extensions like '.gz' or '.tar' that you would like ls
# to colorize below. Put the extension, a space, and the color init string.
# (and any comments you want to add after a '#')
.cmd 01;32 # executables (bright green)
.exe 01;32
.com 01;32
.btm 01;32
.bat 01;32
.sh  01;32
.csh 01;32
.tar 01;31 # archives or compressed (bright red)
.tgz 01;31
.arj 01;31
.taz 01;31
.lzh 01;31
.zip 01;31
.z   01;31
.Z   01;31
.gz  01;31
.bz2 01;31
.bz  01;31
.tz  01;31
.rpm 01;31
.cpio 01;31
.jpg 01;35 # image formats
.gif 01;35
.bmp 01;35
.xbm 01;35
.xpm 01;35
.png 01;35
.tif 01;35