0

I'm trying to get information from a perl script piped to the next command to use in a docker script (so it needs to execute in a single pipeline). For some reason, the stdout from the command is not working correctly.

Here's what I am trying to do:

# perl -e '($prefix) = `nginx -V 2>&1` =~ /configure arguments: (.*)/; print $prefix;' | ../configure $(</dev/stdin) --add-dynamic-module=nginx-upload-module-master

If I try to echo out, the stdin from the first command, then it produces no output.

# perl -e '($prefix) = `nginx -V 2>&1` =~ /configure arguments: (.*)/; print $prefix;' | echo $(</dev/stdin)

# 

Any idea why this is not working as I would suspect? I am using the dash shell.

p.s. I know the first command is working correctly:

# perl -e '($prefix) = `nginx -V 2>&1` =~ /configure arguments: (.*)/; print $prefix;'
--with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-YlUNvj/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --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 --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module

1 Answer 1

2

Dash does support $(…) for command substitution, but </dev/stdin is not a command that outputs anything. It's a sole redirection.

In Bash $(<file) is equivalent to $(cat file), but it's a special case, a syntax supported for user's convenience. Apparently it's not supported in Dash.

If you want this $(</dev/stdin) itself to work in Dash like you expected, use $(cat /dev/stdin). But I don't think $(…) is a good way in the first place. I can see the first command outputs a string containing single-quotes that should be interpreted. Quotes in the output are to protect some spaces. Command substitution does not interpret quotes. Certainly unquoted $(cat /dev/stdin) will split the string in wrong places, but if you quote it then it will form a single argument; in any case the quotes will still be there.

The string from the first command probably should be used with xargs or maybe with eval. I don't know nginx -V, so I cannot tell for sure.

This is how you do it with xargs:

perl -e '($prefix) = `nginx -V 2>&1` =~ /configure arguments: (.*)/; print $prefix;' \
| xargs ../configure --add-dynamic-module=nginx-upload-module-master

xargs will interpret quotes and thus it will create a single argument from --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-YlUNvj/nginx-1.14.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2'.

12
  • # is the dash command prompt as configured on my system. Maybe I should edit for clarity?
    – markf78
    Nov 19, 2022 at 18:50
  • @markf78 Are you trying to say that your perl command prints something that doesn't end with a newline character, so the prompt gets "glued" to the end of the output? And you posted the output with this prompt for some reason? This would explain the trailing #, but it's not obvious. Maybe if I knew perl and if your first snippet didn't contain this trailing " Nov 19, 2022 at 19:22
  • No, sorry, I was trying to say my command prompt itself is a "#" instead of the more common "user@host:~$" or something like that.
    – markf78
    Nov 19, 2022 at 22:51
  • it's my prompt.
    – markf78
    Nov 19, 2022 at 23:18
  • @markf78 So yes, your perl command prints something that doesn't end with a newline character, so the prompt gets "glued" to the end of the output. Sigh… What is your reason for including the prompt in this position in a snippet in your question? IMO it's quite misleading. Nov 19, 2022 at 23:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .