2

The following bash script is expected to echo the current ip of the wan, instead of google "what is my ip".
Error:

./ipChange.txt: line 2: +short: command not found “??

#!/bin/bash
ip=dig +short myip.opendns.com @resolver1.opendns.com
echo “$ip”

Any idea how to fix it? Thx

Fred J.
  • 285

2 Answers2

2

I have an easier oneliner for you:

curl ipecho.net/plain

If you want it in a variable:

myIp=$(curl ipecho.net/plain)
  • 3
    I think it's better to keep the OP's lightweight DNS-based approach instead of using a relatively more expensive HTTP request. – Celada Oct 30 '16 at 20:37
1

Replace

ip=dig +short myip.opendns.com @resolver1.opendns.com

by

ip=$(dig +short myip.opendns.com @resolver1.opendns.com)
Cyrus
  • 12,309