grepは複数の部分文字列と一致し、不足している場合は合格または失敗します。

grepは複数の部分文字列と一致し、不足している場合は合格または失敗します。

nginx -V 2>&1 | \
grep -qi 'nginx/1.9.10\|ngx_pagespeed-release-1.9.32.10\|openssl-1.0.2f\|modsecurity-2.9.‌​0' \
&& echo "has the stuff we need" \
|| echo "missing something"

これは以下に関連しています。

[root@mage2appblock vagrant]# nginx -V
nginx version: nginx/1.9.10
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.2f  28 Jan 2016
TLS SNI support enabled
configure arguments: --user=www-data --group=www-data
--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx
--conf-path=/etc/nginx/nginx.conf --pid-path=/var/run/nginx.pid
--lock-path=/var/lock/subsys/nginx
--error-log-path=/var/log/nginx/error.log
--http-log-path=/var/log/nginx/access.log
--http-client-body-temp-path=/var/cache/nginx/client_temp
--http-proxy-temp-path=/var/cache/nginx/proxy_temp
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp
--http-scgi-temp-path=/var/cache/nginx/scgi_temp
--add-module=/src/nginx/ngx_pagespeed-release-1.9.32.10-beta
--add-module=/src/nginx/modsecurity-2.9.0/nginx/modsecurity 
--with-http_auth_request_module --with-http_sub_module 
--with-http_mp4_module --with-http_flv_module 
--with-http_addition_module --with-http_dav_module
--with-http_gunzip_module --with-http_gzip_static_module 
--with-http_stub_status_module --with-http_sub_module 
--with-http_v2_module --with-http_ssl_module 
--with-openssl=/src/nginx/openssl-1.0.2f 
--with-sha1=/usr/include/openssl
--with-md5=/usr/include/openssl --with-pcre --with-ipv6 
--with-file-aio --with-http_realip_module 
--without-http_scgi_module --without-http_uwsgi_module

部分文字列を変更すると

'nginx/1.9.10\|ngx_pagespeed-release-1.9.32.10\|openssl-1.0.2f\|modsecurity-2.9.‌​0'

到着

'nginx/1.9.10\|ngx_pagespeed-release-1.9.32.10\|openssl-1.0.2f\|modsecurity-2.9.‌​1'

"has the stuff we need"すべてがそこにあるわけではありませんが、私はまだそれを得ます。すべて一致する必要があるか、一致する必要はありません。

ベストアンサー1

awk '/openssl-1.0.2f/ {test1=1} /nginx\/1.9.10/ {test2=1} 
  END { if (test1 && test2) print "has the stuff we need"; 
  else print "missing something"}'

awk必要に応じて終了コードを設定することもできます。

修正する

より短いバージョン(入力に0x1文字が含まれていると仮定すると、改行文字の入力は単一の「行」として扱われます)

awk -v RS='\1' '/openssl-1\.0\.2f/ && /nginx\/1\.9\.10/ {
 print "has the stuff we need"; exit};{print "missing something"; exit(1)}'

おすすめ記事