Howto run a bash compressed script?

Is there a way to run a compressed bash script with "arguments" directly on the fly without unpacking it to a file, and then run the unpacked file?

for example: I need to execute setup-mysql gzip a 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 for the word MAGIC ... in my team below:

gzip -d --stdout /usr/share/doc/wordpress/examples/setup-mysql.gz | MAGIC... -n wordpress localhost 
+3
bash gzip
source share
1 answer

Try the following:

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

A little explanation: with bash -s you tell bash to treat stdin as commands. A double dash means that everything else will be passed as arguments (a single dash seems equivalent, check man bash ).

If you had no argument, you could just do

 gzip -d --stdout file.gz | bash 

Another variant:

 gzip -d --stdout file.gz | bash /dev/stdin "arguments" 
+3
source share

All Articles