Setting the path permanently using shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Setting the path permanently using shell script
# 1  
Old 01-18-2013
Setting the path permanently using shell script

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.
Code:
echo "PATH=$PATH:/opt/quest/bin:/usr/bin/lab" >> /.profile


Last edited by Franklin52; 01-18-2013 at 04:18 AM.. Reason: Please use code tags for data and code samples
# 2  
Old 01-18-2013
Can you please explain more...do you need the symbolic link to .profile file or anything else.
# 3  
Old 01-18-2013
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.
# 4  
Old 01-18-2013
Try this:
Code:
echo "export PATH=${PATH}:/opt/quest/bin:/usr/bin/lab" >> ~/.profile

# 5  
Old 01-18-2013
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 Smilie
# 6  
Old 01-20-2013
You can do it like this:

Code:
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.

Code:
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


Last edited by Chubler_XL; 01-20-2013 at 09:40 PM.. Reason: Wrap long command line
This User Gave Thanks to Chubler_XL For This Post:
# 7  
Old 01-22-2013
It worked. Thanks alot for the help.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

Add directory to path permanently

I ssh in and am trying to add a directory permanently to $PATH in centos 7 and having issues. My current $PATH is echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin but when I do a sudo nano ~/.bashrc # .bashrc # User specific aliases and functions alias... (7 Replies)
Discussion started by: cmccabe
7 Replies

2. Shell Programming and Scripting

Shell Script for Setting Env Variables

Hello All. Good Afternoon. I need one small help regarding setting of env variables for a particular host by getting it from the DB. For ex : 1. I am using LOCALHOST. 2. When I run a ./hostset.sh it should pick up the Oracle home details from associated DB and set it. Please... (1 Reply)
Discussion started by: PavanPatil
1 Replies

3. Shell Programming and Scripting

add path variable permanently

Hi, I have added the path variable as below export... (4 Replies)
Discussion started by: burton
4 Replies

4. Shell Programming and Scripting

setting a shell script variable in awk

The following is part of a larger shell script grep -v "Col1" my_test.log | grep -v "-" | awk '$5 == "Y" {print $1}' instead of printing, can I set set $1 to a variable that the rest of the shell script can read? if $5 == Y, I want to call another shell script and pass $1 as a... (2 Replies)
Discussion started by: guessingo
2 Replies

5. Shell Programming and Scripting

tcsh env setting using shell script

Hi All, I have made a file file usercreate.sh & it has to run in tcsh env & needs some path to be set. my script is as below. ########################## #!/bin/csh setenv PATH "/usr/lib/java/class" setenv LD_LIBRARAY_PATH ########################### but when i am ruuning my script... (1 Reply)
Discussion started by: ajaincv
1 Replies

6. Shell Programming and Scripting

setting a path in bash shell

Hello all, Sorry if the question if stupid but I have no big experience with programming. I am trying to set a path to be used in a makefile.in, for installation of a Fortran code. The makefile.in contains the string $(CODE_NAME) Now, when I type in the bash shell export... (6 Replies)
Discussion started by: laura74
6 Replies

7. IP Networking

Is there any way to add an exception for a port in the firewall setting, permanently?

Hello, I want to add a port in the firewall exception list so that my application can be accessed over network even if firewall is disabled. I am using iptables command to add exception. The problem is, after setting the rule if I change the firewall setting i.e. on/off then it is overwriting... (1 Reply)
Discussion started by: senrooy
1 Replies

8. Shell Programming and Scripting

Error in setting PATH variable in bash shell

Hi, I am new to shell scripting.I tried adding an entry to the path variable like below export PATH=$PATH:/opt/xxx/bin But am getting an error invalid identifier /opt/xxx/bin Can someone tell me the error above and correct me . Thanks and Regards, Padmini (2 Replies)
Discussion started by: padmisri
2 Replies

9. Shell Programming and Scripting

problem in setting classpath in shell script

please send me format for wriiting classpath in shell script this is my shell script --------------- #! /bin/bash javac File1.java /usr/bin/java File1 -------------------------- the script works fine on termianal but in cron it gives me error saying class defination not found ... (1 Reply)
Discussion started by: sari
1 Replies

10. Shell Programming and Scripting

getting a shell script to know it's path

Is it possible in Bash (or any other shell) to get a shell script to know it's own path without having to be part of $PATH or anything like that. I need this cos i want the script to be able to rename the directory in which it resides. is this possible? (6 Replies)
Discussion started by: Nat
6 Replies
Login or Register to Ask a Question