Reputation: 153
I am trying to create a shell script that updates my public ip to the DynU service.
this command works fine in the terminal
wget -O - v4.ident.me 2>/dev/null && echo
The issue comes when I try to integrate the ip obtained with the wget into another wget. I'm trying this script:
#!/bin/bash
myip=wget -O - v4.ident.me 2>/dev/null && echo
echo $myip
echo $0
wget "http://api.dynu.com/nic/update?myip=$myip&username=my-username-comes-here
&password=my-pwd-comes-here"
Don't get confused by the "echo $0" it's there just to test the execution, I will remove it when the script works.
Could you see what I am doing wrong? I appreciate your help.
Upvotes: -1
Views: 21
Reputation: 54733
What you have just sets the variable to that string. If you want to capture the result of executing the command, when you do, then you need to tell the shell to execute the command with $(...):
myip=$(wget -O - v4.ident.me 2>/dev/null)
Upvotes: 1