momigi
momigi

Reputation: 129

Run bash script curled from the web

I wrote a bash script that should be installable from the web. It should take inputs from the user when run. Below is how I did it but it directly terminates the application without prompting the user to input information.

curl www.test.com/script.sh | bash

I read somewhere that stdin is piped to bash that's why it's not prompting anything.

Any help would be great.

Thanks guys

Upvotes: 3

Views: 330

Answers (3)

lxop
lxop

Reputation: 8615

Try

bash -c '`curl www.test.com/script.sh`'

Although this will have problems if the script has single quotes in it.

Failing that, do it in two steps:

curl -o /tmp/script.sh www.test.com/script.sh 
bash /tmp/script.sh

You can save the script anywhere you like, and for better security etc you might want to use tmpfile or something, but running a script straight off the net doesn't sound like high security anyway.

Upvotes: 1

Michael Hoffman
Michael Hoffman

Reputation: 34354

Use process substitution:

bash <(curl www.test.com/script.sh)

Upvotes: 8

Faiz
Faiz

Reputation: 16265

You could try:

 bash -c "$(curl -s www.test.com/script.sh)"

From the bash manpage,

  -c string If the -c option is present, then commands are read from string.  
            If there are arguments after the string, they are
            assigned to the positional parameters, starting with $0.

Upvotes: 1

Related Questions