如何运行bash压缩脚本?

编程入门 行业动态 更新时间:2024-10-11 23:21:18
本文介绍了如何运行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压缩脚本?

本文发布于:2023-11-23 19:11:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   bash

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!