shell之printf

in 系统运维

本文记录的是shell之printf格式化输出.

首先看看其 man page 内容:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
NAME
printf -- formatted output

SYNOPSIS
printf format [arguments ...]

DESCRIPTION
The printf utility formats and prints its arguments, after
the first, under control of the format. The format is a character string which contains three types of objects: plain characters,
which are simply copied to standard output, character escape
sequences which are converted and copied to the standard
output, and format specifications, each of which causes printing
of the next successive argument.

The arguments after the first are treated as strings if the
corresponding format is either c, b or s;otherwise it is evaluated
as a C constant, with the following extensions:

o A leading plus or minus sign is allowed.
o If the leading character is a single or double quote, the value is the ASCII code of the next character.

从上述 man page 内容可以看出:

  1. printf通过format字符串格式化输出其后的arguments
  2. format字符串包含三种类型对象: 普通字符串,该对象输出时会直接拷贝到标准输出STDOUT;字符转义序列,通过字符转义之后输出到标准输出;格式说明符,每一个格式说明符对应输出相应的argument
  3. 如果对应的格式指示符是%c/%b/%s时,相对应的参数都视为字符串,否则它们会被解释为C语言的数字常量: 在其开头可使用正负号标识;如果字符串开头是单引号'或者双引号",那么打印输出的值是紧跟着单引号或者双引号后的那个字符的ASCII
Continue reading

本文记录的是关于shell之echo的知识。

echo是linux中常用的终端命令(command line),其包括:

1
command_name option argument

首先看看echo的 man page:

1
2
3
4
5
6
7
8
9
NAME
echo -- write arguments to the standard output

SYNOPSIS
echo [-n] [string ...]

DESCRIPTION
The echo utility writes any specified operands, separated by single blank (' ') characters and followed
by a newline (`\n') character, to the standard output.

从帮助文档可以看出:

  1. echo是将其后的arguments输出到(STDOUT),通常就是bash界面.
  2. echo是将所有的操作对象,以单一的空格` `分开的字符串,最后紧跟着换行符(‘’),输出到bash
Continue reading
  • page 1 of 1

CaryaLiu

宅男一枚, 在前进的道路上.


iOS开发工程师


成都