I have a need to update IP address
My environment file:
[root@server ~]# cat /etc/environment
ip1=192.168.1.1
ip2=192.168.1.2
My script looks like:
#!/bin/bash
echo ip3=192.168.1.3 >> /etc/environment
source /etc/environment
Problem is, it does not "source" on the file.
I have go back to the command line and run:
[root@server ~]# echo $ip3
[root@server ~]# source /etc/environment
[root@server ~]# echo $ip3
192.168.1.3
How do I source a file from a script?
The
source
ing inside of the script happens inside of the shell that was forked to run your script. If you want to have your script affect your current shell then you have tosource
your script too, not just run it.