-1
#hello world in bash
s="hello world"
printf "%s\n" $s
我预计输出为hello world\n
但hello\nworld\n
在bash使用printf命令
任何人都可以解释这一点?
#hello world in bash
s="hello world"
printf "%s\n" $s
我预计输出为hello world\n
但hello\nworld\n
在bash使用printf命令
任何人都可以解释这一点?
总之"word splitting"。 $s
变量的扩展然后被分割成单词并且printf
看到两个参数并单独使用它们。
引用您的变量扩展,以防止这种(你做了你的变量赋值的方式):
s="hello world"
printf '%s\n' "$s"