-sharp!/usr/bin/env bash
time=$(date)
nginxConfigPath=$(nginx -t)
echo "datetime" $time
echo "config path" $nginxConfigPath
execute the above shell script file, and the result is
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
datetime Fri Nov 16 14:27:14 CST 2018
theoretically, the variable nginxConfigPath should have a value.
when the actual result is, the result of the nginx-t command is already displayed when it is defined.