Assign output to variable in Bash [duplicate] Assign output to variable in Bash [duplicate] bash bash

Assign output to variable in Bash [duplicate]


In shell, you don't put a $ in front of a variable you're assigning. You only use $IP when you're referring to the variable.

#!/bin/bashIP=$(curl automation.whatismyip.com/n09230945.asp)echo "$IP"sed "s/IP/$IP/" nsupdate.txt | nsupdate


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