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
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
相关文章推荐
- postgresql 在linux上的源码安装
- github使用(linux)
- 查看Linux系统相关版本信息
- CentOS 6.4 服务器版安装教程(超级详细图解)
- Linux Kernel 中 Workqueue 使用系统默认队列和创建队列的方法
- linux基础编程 多线程中的互斥锁 pthread_mutex_lock
- Linux下计划任务 crontab
- centos 下安装.net core
- Centos 7 相关操作与配置
- Linux操作系统基础解析之(三)——基本命令行操作及获得帮助的方法
- Linux系统资源监控--linux命令、nmon和spotlight
- 《Linux4.0设备驱动开发详解》笔记--第二十一章:Linux设备驱动的调试
- 《Linux4.0设备驱动开发详解》笔记--第二十章:Linux芯片级移植及底层驱动
- 《Linux4.0设备驱动开发详解》笔记--第十八章:ARM Linux设备树
- 《Linux4.0设备驱动开发详解》笔记--第十六章:USB主机、设备与Gadget驱动
- 不同系统的换行符号
- centos 7 安装配置mysql
- Linux用户切换
- linux 正则表达式
- centos 7 安装与配置java