the output of "nginx -V" is a mess.

nginx version: nginx/1.9.3 (Ubuntu) built with OpenSSL 1.0.2d 9 Jul 2015 TLS SNI support enabled configure arguments: --with-cc-opt='-g -O2 -fPIE -fstack-protector-strong -Wformat -Werror=format-security -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -fPIE -pie -Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-

So, I write a simple script, redirect the err output to stdout and split the whole line:

nginx -V 2>&1 | sed -r 's/--/\\n/g'

it didn't work.

nginx -V 2>&1 | sed -r s/--/\\n/g

this works, I just don't know why.

  • @don_crissti ok~
    – lovespring
    Feb 22, 2016 at 18:38
  • 2
    \\n between single quotes is taken literally, that is \\ and n so all occurrences of -- are replaced with a backslash and a n. Without quotes the \\n resolves to \n (i.e. newline symbol). Feb 22, 2016 at 18:42
  • @don_crissti thank you~, you are right~
    – lovespring
    Feb 22, 2016 at 19:00

1 Answer 1


Just to test:

$ echo "configure arguments: --with-cc-opt=" | | sed -r 's/--/\\n/g'

Doesn't work. But this:

$ echo "configure arguments: --with-cc-opt=" | sed -r 's/--/\n/g'

Does work. As this, also:

$ echo "configure arguments: --with-cc-opt=" | sed -r s/--/\\n/g

In short: The '\\n' does not work, it is interpreted as a backslash \ and a n. Removing either one of the quoting mechanisms corrects the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.