【发布时间】:2012-06-28 15:32:57
【问题描述】:
如果字符串为空,我正在尝试使用awk 打印特定文本。在以下情况下它可以正常工作
noob@noob:~$ echo "" | awk '{if ($0=="") print "not playing"}'
not playing
但是当我尝试在以下情况下采取类似的方法时,它不起作用
noob@noob:~$ mpc current | awk '{if ($0=="") print "not playing"}'
noob@noob:~$
如果没有歌曲正在播放,我相信mpc current 的输出是一个空字符串。
noob@noob:~$ mpc current
noob@noob:~$ #empty string
那么,我对empty string 的假设是错误的吗?
【问题讨论】:
-
mpc current | awk '{print "X$0X"}'的结果是什么 -
打印
nothing。它的输出与我上面提到的mpc current相同。 -
awk处理“行”。如果mpc current没有输出,则没有要处理的行。 -
@Noob 只是为了确认mpc current的输出不是" ",(即单个空格)