使用 'printf' 命令可以在终端中输出格式化的字符串内容。

例如:

printf 'Hello, %s!
' 'world'

这将输出:

Hello, world!

'printf' 命令类似于 C 语言中的 'printf' 函数,可以使用格式化字符串来控制输出内容的格式。

格式化字符串语法:

  • '%' 符号用于标识格式化指令。
  • 紧随 '%' 符号的字符表示格式类型。
  • 例如:'%s' 用于输出字符串,'%d' 用于输出整数,'%f' 用于输出浮点数。

示例:

# 输出字符串
printf 'Hello, %s!
' 'world'

# 输出整数
printf 'The number is: %d
' 123

# 输出浮点数
printf 'The value is: %f
' 3.14159

更多格式化指令和用法请参考相关文档。

如何在终端中输出格式化字符串? - 使用 printf 命令