我试图将cURL的输出赋值给一个变量,就像这样:
#!/bin/sh
$IP=`curl automation.whatismyip.com/n09230945.asp`
echo $IP
sed s/IP/$IP/ nsupdate.txt | nsupdate
然而,当我运行脚本发生以下情况:
./update.sh: 3: =[我的IP地址]:not found
我如何才能得到输出到$IP正确?
我试图将cURL的输出赋值给一个变量,就像这样:
#!/bin/sh
$IP=`curl automation.whatismyip.com/n09230945.asp`
echo $IP
sed s/IP/$IP/ nsupdate.txt | nsupdate
然而,当我运行脚本发生以下情况:
./update.sh: 3: =[我的IP地址]:not found
我如何才能得到输出到$IP正确?
在shell中,你不把$放在你赋值的变量前面。只有在引用变量时才使用$IP。
#!/bin/bash
IP=$(curl automation.whatismyip.com/n09230945.asp)
echo "$IP"
sed "s/IP/$IP/" nsupdate.txt | nsupdate
更复杂的事情也是如此……从实例中获取ec2实例区域。
INSTANCE_REGION=$(curl -s 'http://169.254.169.254/latest/dynamic/instance-identity/document' | python -c "import sys, json; print json.load(sys.stdin)['region']")
echo $INSTANCE_REGION