linux - How to modify /etc/environment from a bash script -
currently, i'm trying automate procedure utilize @ work. whenever install oracle's jdk, need manually add together our global path
variable. here's excerpt procedure :
sudo vi /etc/environment add together @ origin of path : "/opt/jdk1.6.0_45/bin:"
here content of /etc/environment
on computer :
path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
here after modification :
path="/opt/jdk1.6.0_45/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
do not forget file not script, rather file containing key=values. file stores system-wide locale , path settings.
my question is how can add together new path path
variable /etc/environment
without involving manual operation, preferably using bash script. additionnaly, avoid seeing jdk path added more 1 time if run resulting script twice.
you can using sed first delete , insert jdk path:
#!/bin/bash sed -e 's|/opt/jdk1.6.0_45/bin:||g' -i /etc/environment sed -e 's|path="\(.*\)"|path="/opt/jdk1.6.0_45/bin:\1"|g' -i /etc/environment
linux bash environment-variables
No comments:
Post a Comment