I am attempting to run a bash command in my python script, but it is failing with:
sh: -c: line 0: syntax error near unexpected token('`
The script is pretty simple...
import os
os.system('bash <(curl -f -L -sS https://ngxpagespeed.com/install) --assume-yes --nginx-version latest -a "--prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/media/cache/nginx/client_temp --http-proxy-temp-path=/media/cache/nginx/proxy_temp --http-fastcgi-temp-path=/media/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/media/cache/nginx/uwsgi_temp --http-scgi-temp-path=/media/cache/nginx/scgi_temp --user=www-data --group=www-data --with-file-aio --with-threads --with-ipv6 --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-http_xslt_module --with-http_image_filter_module --with-stream --with-stream_ssl_module"')
But I cannot see where I am going wrong with it.
The exact command run in shell works fine:
bash <(curl -f -L -sS https://ngxpagespeed.com/install) --assume-yes \
--nginx-version latest -a "--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx --modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/media/cache/nginx/client_temp \
--http-proxy-temp-path=/media/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/media/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/media/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/media/cache/nginx/scgi_temp --user=www-data \
--group=www-data --with-file-aio --with-threads --with-ipv6 \
--with-http_addition_module --with-http_auth_request_module \
--with-http_dav_module --with-http_flv_module --with-http_gunzip_module \
--with-http_gzip_static_module --with-http_mp4_module \
--with-http_random_index_module --with-http_realip_module \
--with-http_secure_link_module --with-http_slice_module \
--with-http_ssl_module --with-http_stub_status_module \
--with-http_sub_module --with-http_v2_module --with-mail \
--with-mail_ssl_module --with-http_xslt_module \
--with-http_image_filter_module --with-stream --with-stream_ssl_module"
Any ideas on how I can fix this?
<(...), but the error report sayssh: -c: line 0: syntax error near unexpected token '('. Note that it sayssh, notbash. I'd try to use/bin/bashin theos.systeminvocation; maybe you getshsubstituted forbashin the env where you run the Python code.bash <(echo "echo 'It worked'"). I'd also look atsubprocessmodule that might help sidestep the wrong shell issue by not invoking the user's shell at all.subprocessdoesn't help in and of itself -- using it withshell=Truestill uses/bin/sh-- but withshell=False, it gives the user full control of which, if any, shell is used.system()doesn't use "the user's" shell -- it's hardcoded to/bin/sh(as well it should be -- that way it's guaranteed to be POSIX-compliant, rather than whatever random shell someone decides they want to use interactively; otherwise, someone usingfishorplanckwould break a whole lot of programs).os.systemdoes not allow to run without a shell;shell=False,subprocessjust callsexecvpwithout invoking a shell.