howto run a bash compressed script?

随声附和 提交于 2020-01-02 08:16:32

问题


There is a way to run compressed bash script with 'arguments' directly on the fly without decompressing it in a file and then running the decompressed file ?

for example: i need to execute the setup-mysql gzip compressed script with some given arguments: "-n", "wordpress", "locahost", without decompressing the script first and then executing.

What i'm looking for is a replacement of the word MAGIC... in my command below:

gzip -d --stdout /usr/share/doc/wordpress/examples/setup-mysql.gz | MAGIC... -n wordpress localhost

回答1:


Try this:

gzip -d --stdout file.gz | bash -s -- "-n wordpress localhost"

A little explanation: with bash -s you're telling bash to process stdin as commands. The double dash means that everything that follows will be passed as arguments (a single dash seems to be equivalent, check man bash).

If you didn't have any arguments to pass you could just do

gzip -d --stdout file.gz | bash

Another option is:

gzip -d --stdout file.gz | bash /dev/stdin "arguments"


来源:https://stackoverflow.com/questions/19916879/howto-run-a-bash-compressed-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!