Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

howto run a bash compressed script?

Tags:

bash

gzip

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
like image 816
Zskdan Avatar asked May 18 '26 21:05

Zskdan


1 Answers

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"
like image 90
jlhonora Avatar answered May 21 '26 00:05

jlhonora