2

I have a web app that simply returns an IP address. I want to pass that IP result to another batch script that fires off an application that's supposed to connect to that IP address.

Here's my test:

curl http://silvo.uk.to/IPReg.dll/GetIP | bash starttelem2.sh

For testing, starttelem2.sh only contains:

#!/bin/sh
echo "THE IP IS " $1

However, when I call the above curl with pipe I get what appears to be the curl download progress.

How can I simply pass the result of the curl call to my bash script?

1 Answer 1

2

As you have used positional parameter (argument) 1 ($1) inside the script, use command substitution to pass the IP address from curl as the first argument:

bash starttelem2.sh "$(curl -s http://silvo.uk.to/IPReg.dll/GetIP)"

$(curl -s http://silvo.uk.to/IPReg.dll/GetIP) is command substitution, which will be replaced by the standard output of the curl command inside. The -s option causes curl to not show any progress info on STDERR.

Note that, you have used the shebang as sh but running the script as an argument to bash, as bash is a superset of sh, you should consider making the shebang as bash too, if you don't have any specific reason not to.

3
  • Thanks, however, I still get the download progress in the result: % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 13 100 13 0 0 7 0 0:00:01 0:00:01 --:--:-- 7 THE IP IS 41.185.26.153 Sep 7, 2016 at 18:53
  • @HeinduPlessis Check my edits, you need -s option to silent curl.
    – heemayl
    Sep 7, 2016 at 18:54
  • Wow you guys are too fast! Thanks, working perfectly! I'll look into the bash / shebang business, not familiar with the terms. Thanks again. Sep 7, 2016 at 18:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .