Injecting ip address into command prompt
You specifically asked for verbose output from curl in the second command line, which accounts for most of the output. You should remove -v
. Then, to suppress the progress meter, use -s
(in both commands). This should leave you with no output, unless there is an error.
It would be better if you ran this at startup and wrote the resulting IP address to a file, and then simply read the contents of that file in your bash profile. (This assumes that the IP address doesn't change while the instance is running, which AFAIK doesn't happen.)
Consider a local startup script like this:
#!/usr/bin/env bash
TOKEN=`curl -s -X PUT -H "X-aws-ec2-metadata-token-ttl-seconds: 21600" http://169.254.169.254/latest/api/token`
curl -s -H "X-aws-ec2-metadata-token: \$TOKEN" -o /tmp/local-ipv4 http://169.254.169.254/latest/meta-data/local-ipv4
Now you can read it in your bash profile:
IP=$(cat /tmp/local-ipv4)