# - 后直接按 tab,C 是补全上去的
% print -C
-- option --
-C -- print arguments in specified number of columns
-D -- substitute any arguments which are named directories using ~ notation
-N -- print arguments separated and terminated by nulls
...
print 命令选项功能介绍
这里以常用程度的顺序依次介绍所有的选项,另外文末有“print 选项列表”方便查询。
-l 用于分行输出字符串:
# 每个字符串一行,字符串列表是用空格隔开的
% print -l aa bb
aa
bb
# 也可以接数组,数组相关的内容之后会讲到
# 命令后的多个字符串都可以用数组取代,效果是相同的
% array=(aa bb)
% print -l $array
aa
bb
# print -o 对字符串升序排列
% print -o a d c 1 b g 3 s
1 3 a b c d g s
# print -O 对字符串降序排列
% print -O a d c 1 b g 3 s
s g d c b a 3 1
# 加 -i 参数后,对大小写不敏感
% print -oi A B C a c A B C
A a A B B C c C
# 不加 -i 的话小写排在大写的前面
% print -o A B C a c A B C
a A A B B c C C
-r 用于不对字符串进行转义。print 默认是会对转义字符进行转义的,加 -r 后会原样输出:
% print -r '\n'
\n
-c 用于将字符串按列输出。如果对自动决定的列数不满意,可以用 -C 指定列数:
% print -c a bbbbb ccc ddddd ee ffffff gg hhhhhh ii jj kk
a ccc ee gg ii kk
bbbbb ddddd ffffff hhhhhh jj
-C 用于按指定列数输出字符串:
# 从上到下
% print -C 3 a bb ccc dddd ee f
a ccc ee
bb dddd f
% print -C 3 a bb ccc dddd ee f g
a dddd g
bb ee
ccc f
# 加 -a 后,改成从左向右
% print -a -C 3 a bb ccc dddd ee f g
a bb ccc
dddd ee f
g
-- print format specifier --
-- leave one space in front of positive number from signed conversion
- -- left adjust result
. -- precision
' -- thousand separators
* -- field width in next argument
# -- alternate form
% -- a percent sign
+ -- always place sign before a number from signed conversion
0 -- zero pad to length
b -- as %s but interpret escape sequences in argument
c -- print the first character of the argument
E e -- double number in scientific notation
f -- double number
G g -- double number as %f or %e depending on size
i d -- signed decimal number or with leading " numeric value of following character
n -- store number of printed bytes in parameter specified by argument
o -- unsigned octal number
q -- as %s but shell quote result
s -- print the argument as a string
u -- unsigned decimal number
X x -- unsigned hexadecimal number, letters capitalized as x