深入探索Shell的字符串输入输出与命令行处理机制
1. 额外的bash printf说明符
除了标准的说明符,bash shell(以及其他符合POSIX标准的shell)还接受两个额外的说明符,不过这会牺牲在其他shell或UNIX其他地方的 printf 命令版本中的可移植性。
- %b :当使用 %b 代替 %s 时,它会展开参数字符串中的 echo 风格的转义序列。示例如下:
$ printf "%s\n" 'hello\nworld'
hello\nworld
$ printf "%b\n" 'hello\nworld'
hello
world
- %q :当使用
%q代替%s时,它会以适合作为shell输入的方式打印字符串参数。示例如下:
$ printf "%q\n" "greetings to the world"
greetings\ to\ the\ world
2. read命令
read 命令是shell字符串输入输出功能的另一半,它允许将值读入shell变量。基本语法为:
超级会员免费看
订阅专栏 解锁全文
12

被折叠的 条评论
为什么被折叠?



