Assign output to variable in Bash

前端 未结 2 407
闹比i
闹比i 2020-12-02 06:34

I\'m trying to assign the output of cURL into a variable like so:

#!/bin/sh
$IP=`curl automation.whatismyip.com/n09230945.asp`
echo $IP
sed s/IP/$IP/ nsupdat         


        
2条回答
  •  独厮守ぢ
    2020-12-02 07:17

    Same with something more complex...getting the ec2 instance region from within the instance.

    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
    

提交回复
热议问题