bourne shell 单引号、双引号 &反引号问题
/!bin/sh
if [ "`echo $desc $status | awk -F"," '{print $3}' | awk -F" " '{print $1}' | sed '/^$/d'`" != "OK" ]; then
echo "howdy dody"
fi
echo $desc $status | awk -F"," '{print $3}' | awk -F" " '{print $1}' | sed '/^$/d'
第一个 if 条件不会运行,我猜这是因为引用不当,但我无法弄清楚。
预先感谢您的任何帮助。
/!bin/sh
if [ "`echo $desc $status | awk -F"," '{print $3}' | awk -F" " '{print $1}' | sed '/^$/d'`" != "OK" ]; then
echo "howdy dody"
fi
echo $desc $status | awk -F"," '{print $3}' | awk -F" " '{print $1}' | sed '/^$/d'
First if-condition won't run, im guessing it's because of improper quotation, but i can't figure it out.
Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果将测试包装在函数中,则编写测试会容易得多:
这样,您可以验证它是否正常工作。一旦你获得了这种信心
或
It is much easier to write your test if you wrap it in a function:
This way, you can verify that it works correctly. Once you gained this confidence
or
如果您使用 Bash,我建议使用
$(...)
而不是反引号。您收到什么错误消息?我的猜测是 awk 的-F","
选项没有被正确引用。尝试插入\
来转义引号。If you're using Bash, I'd recommend
$(...)
instead of back-quotes. What error messages do you get? My guess is that the-F","
option to awk is not being quoted properly. Trying inserting\
to escape the quotation marks.乍一看,您可能想尝试转义一些双引号
:
At first glance, you might want to try escaping some of the double quotes:
to
转义双引号当然是一个好主意,但看起来 $3 和 $1 旨在由 awk 解释。相反,它们由您的 shell 解释。您可能想转义“$”。 (您可能在 shell 中具有有意义的 $1 和 $3 值,但可能性不大。)
Escaping the double quotes is certainly a good idea, but it looks like the $3 and the $1 are intended to be interpreted by awk. They are being interpreted by your shell instead. You probably want to escape the '$'s. (It is possible that you have meaningful values for $1 and $3 in the shell, but not likely.)
您还可以在
-F
选项的参数周围使用单引号,就像在其他参数周围使用单引号一样:You can also use single quotes around the argument to the
-F
option as you have around other arguments: