Why does my script fail to read input when executed via curl?

0
2
Asked By CuriousCat42 On

I've got a Bash script that prompts for a 'y/n' response and works perfectly when I run it locally. However, when I try to execute it using curl like this: `curl -sSL https://url.com/test.sh | bash -x`, it keeps returning an 'invalid response' message, even if I give a valid response. I don't understand why it behaves this way when run through curl versus running it directly. What could be going wrong?

2 Answers

Answered By TechGuru88 On

First off, what does the URL actually output when you curl it? If you run `curl -sSL https://url.com/test.sh`, you'll see the script itself. That way you can check it's what you expect.

Answered By CodeWizard34 On

Running scripts like that with curl can be risky! When you use pipes, the script is cut off from the terminal interaction it needs. Essentially, it’s not able to read input from stdin. If you want to run it like this safely, consider using process substitution instead. For example: `bash -x <(curl -sSL https://url.com/test.sh)`. This will give your script proper access to the terminal.

CuriousCat42 -

Thanks for the tip! I'll try that!

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.