I'm trying to write a Linux shell script to change an environment variable 'ROS_IP' to my current IP address.
printenv | grep "ROS_IP"
returns ROS_IP=192.168.1.10
The command
ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/'
returns my current ip address 192.168.1.2 which is correct
Here is my shell script
#!/bin/bash
#Command to get current IP address and set the output to a variable 'var'
var=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
#Make sure var is the correct IP
echo $var
#Set ROS_IP
export ROS_IP=$var
#end script
after the script has run, running the command
printenv | grep "ROS_IP"
still returns the old output ROS_IP=192.168.1.10
How can I fix this issue?