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)

1

1 Answer 1

3

nginx writes version on stderr, not on stdout.

To capture stderr you can redirect it to stdout:

b=$(nginx -v 2>&1)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.