如何运行bash压缩脚本? [英] howto run a bash compressed script?

查看:90
本文介绍了如何运行bash压缩脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以直接运行带有参数"的压缩bash脚本,而无需将其解压缩到文件中,然后再运行解压缩的文件吗?

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 ?

例如:我需要执行带有某些给定参数的setup-mysql gzip压缩脚本:-n","wordpress","locahost",而无需先解压缩脚本然后执行.

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.

我要查找的是以下命令中的MAGIC ...的替换:

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

推荐答案

尝试一下:

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

一点解释:使用bash -s,您告诉bash作为命令处理stdin.双破折号表示后面的所有内容都将作为参数传递(单个破折号似乎是等效的,请选中man bash).

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

另一个选择是:

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

这篇关于如何运行bash压缩脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆