The goal of the script below is to test nginx configuration and if successful it will then restart the service as shown.
#!/bin/bash echo "checking nginx config..." if sudo nginx -t | grep -q 'successful'; then echo "restaring nginx..." sudo systemctl restart nginx fi When this script is executed it prints
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful However, I wonder why the statement inside the if-statement does not run even if the result text contains "successful"
if sudo nginx -t; then?