奇怪了 printf 的输出

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
Echol
帖子: 16
注册时间: 2010-07-24 16:02

奇怪了 printf 的输出

#1

帖子 Echol » 2010-08-16 15:42

代码: 全选

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!'
这是为什么?
Pain is short and joy is eternal.
BLOG: http://hi.baidu.com/mcmlxxxviii
gzbao9999
帖子: 627
注册时间: 2008-11-08 18:34

Re: 奇怪了 printf 的输出

#2

帖子 gzbao9999 » 2010-08-16 15:53

关键在%s,%s 这两个占位符
hello world(hello占位到第一位置上 world占位到第二个位置上)
气血鼓荡,身体发胀,偶飘上头,三时舒畅
aerofox
帖子: 1453
注册时间: 2008-05-24 8:30

Re: 奇怪了 printf 的输出

#3

帖子 aerofox » 2010-08-16 18:43

在 ! 前加上反斜杠。
tusooa
帖子: 6548
注册时间: 2008-10-31 22:12
系统: 践兔
联系:

Re: 奇怪了 printf 的输出

#4

帖子 tusooa » 2010-08-16 20:00

!是shell特殊字符,需要转义或者放在单引号里面

代码: 全选

] ls -ld //
回复