I try to redirect the output of an init.d command to a variabl开发者_运维问答e without displaying it on screen, but this does not work. For example this works :
$> var=`uname -a`
$> echo $var
$> Linux
But not this :
$> var=`/etc/init.d/nginx reload`
$> the configuration file /etc/nginx/nginx.conf syntax is ok
configuration file /etc/nginx/nginx.conf test is successful
$> echo $var
$> Reloading nginx configuration: nginx.
How can we do to return nothing on the screen please? Thanks.
Nico
nginx -t
writes those messages on standard error, not on standard output, so you need to capture those too:
# var=`nginx -t 2>&1`
# echo $var
the configuration file /etc/nginx/nginx.conf syntax is ok configuration file /etc/nginx/nginx.conf test is successful
#
It is entirely possible it is going to stderr instead of stdout. You could try something like this:
var=`/etc/init.d/nginx reload 2>&1`
to test.
精彩评论