分页: 1 / 1

奇怪了 printf 的输出

发表于 : 2010-08-16 15:42
Echol

代码: 全选

printf "The first program always prints '%s, %s!' \n" hello world
输出它... :em20
printf "The first program always prints '%s, %s'/etc/init.d/vboxdrv setup' \n" hello world
The first program always prints 'hello, world'/etc/init.d/vboxdrv setup'
而不是
The first program always prints 'hello, world!'
这是为什么?

Re: 奇怪了 printf 的输出

发表于 : 2010-08-16 15:53
gzbao9999
关键在%s,%s 这两个占位符
hello world(hello占位到第一位置上 world占位到第二个位置上)

Re: 奇怪了 printf 的输出

发表于 : 2010-08-16 18:43
aerofox
在 ! 前加上反斜杠。

Re: 奇怪了 printf 的输出

发表于 : 2010-08-16 20:00
tusooa
!是shell特殊字符,需要转义或者放在单引号里面