1

Could someone explain me the difference between these two cases and tell me why $b is empty? Thank you.

$ a=$(uname -o)
$ echo $a
GNU/Linux
$ b=$(nginx -v)
nginx version: nginx/1.17.4
$ echo $b

$ _

I was expecting to use the version of Nginx installed to download its source code, something like this:

$ wget http://nginx.org/download/nginx-$(nginx -v | cut -d"/" -f2).tar.gz
--2019-09-27 20:06:54--  http://nginx.org/download/nginx-.tar.gz
HTTP request sent, awaiting response... 404 Not Found

Using: GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)

jmox
  • 21
  • 5

1 Answers1

3

nginx writes version on stderr, not on stdout.

To capture stderr you can redirect it to stdout:

b=$(nginx -v 2>&1)
KamilCuk
  • 120,984
  • 8
  • 59
  • 111