![bash 스크립트 echo wan ip [중복]](https://linux55.com/image/97566/bash%20%EC%8A%A4%ED%81%AC%EB%A6%BD%ED%8A%B8%20echo%20wan%20ip%20%5B%EC%A4%91%EB%B3%B5%5D.png)
다음 bash 스크립트는 Google의 "내 IP는 무엇입니까" 대신 wan의 현재 IP를 에코할 것으로 예상됩니다.
실수:
./ipChange.txt: 2행: +short: 명령을 찾을 수 없음 "?
#!/bin/bash
ip=dig +short myip.opendns.com @resolver1.opendns.com
echo “$ip”
문제를 해결하는 방법을 아시나요? 감사해요
답변1
나는 당신을 위해 더 간단한 한 줄의 내용을 가지고 있습니다.
curl ipecho.net/plain
변수에 넣으려면 다음을 수행하십시오.
myIp=$(curl ipecho.net/plain)
답변2
바꾸다
ip=dig +short myip.opendns.com @resolver1.opendns.com
통과
ip=$(dig +short myip.opendns.com @resolver1.opendns.com)