如果使用bash script/python/perl script
,是否可以显示没有字符串的命令的输出。
curl -i http://www.google.com
HTTP/1.1 302 Found
Location: http://www.google.com.hk/
Cache-Control: private
Content-Type: text/html; charset=UTF-8
我想做的是:
302 is missed
发布于 2012-12-14 07:14:42
您可以使用curl|grep
沉默的结果作为测试:
if ! `curl -i -s http://www.google.com|grep -q 302` ; then echo "302 is missed" ; fi
发布于 2012-12-14 07:10:40
$ grep -q 302 << EOF || echo "302 is missed"
> HTTP/1.1 302 Found
> Location: http://www.google.com.hk/
> Cache-Control: private
> Content-Type: text/html; charset=UTF-8
> EOF
$ grep -q 302 << EOF || echo "302 is missed"
> HTTP/1.1 312 Found
> Location: http://www.google.com.hk/
> Cache-Control: private
> Content-Type: text/html; charset=UTF-8
> EOF
302 is missed
发布于 2012-12-14 07:11:07
你的意思是这样的:
if [ ! `echo 302 | grep 302` ] ; then echo 302 is missed; fi
可以用任何适当的命令替换echo 302
..。
相当于:
echo 302 | grep 302 > /dev/null || echo "302 is missed"
https://stackoverflow.com/questions/13881158
复制相似问题