您的位置:首页 > 运维架构 > Linux

Linux命令之echo,printf-2

2016-05-21 14:43 344 查看
echo

echo 应该是linux用得最多的输出命令,作用是将参数打印到标准输出,或者重定向到目标位置。

ECHO(1)                     User Commands                    ECHO(1)

NAME

       echo - display a line of text

SYNOPSIS

       echo [SHORT-OPTION]... [STRING]...

       echo LONG-OPTION

DESCRIPTION

       Echo the STRING(s) to standard output.

       -n     do not output the trailing newline        #省略换行

       -e     enable interpretation of backslash escapes      #开启转义序列

       -E     disable interpretation of backslash escapes (default)          #关闭转义序列(默认)

比如简单的输出:

[cmd@localhost ~]$ echo hello world

hello world

[cmd@localhost ~]$ echo "hello world"

hello world
-n选项

[cmd@localhost ~]$ echo -n "hello world"

hello world[cmd@localhost ~]$

转义序列

       \\     backslash                                           #反斜线

[cmd@localhost ~]$ echo -e "hello world\\"

hello world\

       \a     alert (BEL)                                         #警告

[cmd@localhost ~]$ echo -e "\ahello world"

hello world                                                        #会听到响一声

       \b     backspace                                         #退格

       \c     produce no further output                  #忽略后面的字符,包括换行符

[cmd@localhost ~]$ echo -e "hello world\chehe"

hello world[cmd@localhost ~]$

       \e     escape                                              

       \f     form feed

       \n     new line                                             #换行

       \r     carriage return                                    #回车

       \t     horizontal tab                                      #水平制表符

       \v     vertical tab                                         #垂直制表符

       \0NNN  byte with octal value NNN (1 to 3 digits)

       \xHH   byte with hexadecimal value HH (1 to 2 digits)

printf
PRINTF(1)                   User Commands                  PRINTF(1)

NAME

       printf - format and print data

SYNOPSIS

       printf FORMAT [ARGUMENT]...

       printf OPTION

DESCRIPTION

       #转义序列跟echo差不多

       \"     double quote

       \\     ackslash

       \a     alert (BEL)

       \b     backspace

       \c     produce no further output

       \e     escape

       \f     form feed

       \n     new line

       \r     carriage return

       \t     horizontal tab

       \v     vertical tab

       \NNN   byte with octal value NNN (1 to 3 digits)

       \xHH    byte with hexadecimal value HH (1 to 2 digits)

       \uHHHH                       Unicode  (ISO/IEC 10646) character with hex value HHHH (4 digits)

       \UHHHHHHHH            Unicode character with hex value HHHHHHHH (8 digits)
       %%     a single %

       %b     ARGUMENT as a string  with  '\'  escapes  interpreted,

                 except that octal escapes are of the form \0 or \0NNN

     printf几乎复制了c库里的printf()函数的所有功能,用法也类似。

[cmd@localhost ~]$ printf "hello world\n"

hello world

[cmd@localhost ~]$ printf "hello world %s %s %s\n" take it easy

hello world take it easy

    
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: