I'm trying to set the path permanently through a shell script. (/opt/quest/bin:/usr/bin/lab to /.profile.) I tired using echo option like below but it doesn't work. Please suggest me the right way to do so.
echo "PATH=$PATH:/opt/quest/bin:/usr/bin/lab" >> /.profile
Can you please explain more...do you need the symbolic link to .profile file or anything else.
I just want to set the path permanently, I mean it should not change even after reboot.
echo $PATH should my extension permanently.
Please let me know if I'm confusing you.
Yoda
January 17, 2013, 11:43pm
4
Try this:
echo "export PATH=${PATH}:/opt/quest/bin:/usr/bin/lab" >> ~/.profile
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/usr/java14/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/bin:/usr/ccs/bin:/usr/pge/bin:/usr/pge/adm:/usr/pge/apps:/usr/local/bin
exportPATH=/opt/quest/libexec/oat:/opt/quest/bin:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/usr/java14/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/bin:/usr/ccs/bin:/usr/pge/bin:/usr/pge/adm:/usr/pge/apps:/usr/local/bin:/opt/quest/bin:/usr/bin/lab
Actually, it didn't worked too. It a added new line to .profile file, which is completely distracted. I actually need it like below.
PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java14/jre/bin:/usr/java14/bin:/usr/local/bin:/usr/local/sbin:/usr/local/bin:/bin:/usr/ccs/bin:/usr/pge/bin:/usr/pge/adm:/usr/pge/apps:/usr/local/bin:/opt/quest/bin:/usr/bin/lab
Sorry for the confusion :o
You can do it like this:
sed -i 's;^PATH=\(.*\)$;PATH=\1/opt/quest/bin:/usr/bin/lab;' ~/.profile
However if the .profile PATH already has /opt/quest/bin or /usr/bin/lab they will be duplicaed. This longer version will remove the path entries first if they exist before putting them back on the end.
sed -i -e 's;:*/opt/quest/bin:;:;' \
-e 's;:*/opt/quest/bin$;;' \
-e 's;:*/usr/bin/lab:;:;' \
-e 's;:*/usr/bin/lab$;;' \
-e 's;^PATH=\(.*\)$;PATH=\1:/opt/quest/bin:/usr/bin/lab;' ~/.profile
1 Like
It worked. Thanks alot for the help.