3

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
Zskdan
  • 799
  • 8
  • 17

1 Answers1

3

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"
jlhonora
  • 10,179
  • 10
  • 46
  • 70
  • 2
    `... bash -s -- -n wordpress localhost` would be better, so that the script sees each argument separately, rather than a single word. – chepner Nov 11 '13 at 22:56
  • @jlhonora, thinks, that what's i'm looking for, but why you say that's machine-dependent ? – Zskdan Nov 11 '13 at 23:02
  • @Zskdan I finally dropped that comment since I couldn't back it up with any references. I just thought that '/dev/stdin' may not be present or not readable in certain machines and linux distros, but that not seems to be the case. – jlhonora Nov 11 '13 at 23:18
  • 1
    @jlhonora `bash` implements those aliases internally if those files aren't actually present in the file system. – chepner Nov 12 '13 at 13:28