Adding to the end of the path in .profile


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Adding to the end of the path in .profile
# 1  
Old 04-09-2016
Adding to the end of the path in .profile

Hi there,

I have the following in my path:
Code:
export PATH=/usr/bin:/usr/sbin

But I want to change it programmatically(for the purpose of JBoss automatic(ansible) installs) to:
Code:
export PATH=/usr/bin:/usr/sbin:/usr/jdk/jdk1.8.0_60

and after that I need to insert the JAVA_HOME programmatically, but not now...

So, after trawling the www for answers... I thought that this one is the least confusing (not allowed to insert the http Smilie

unix.com >> shell-programming-and-scripting >> 32168-replace-directory-path-another-file.html


Code:
sed 's_export PATH=/usr/bin:/usr/sbin_export PATH=/usr/bin:/usr/sbin:/usr/jdk/jdk1.8.0_60_g' .profile > xx

But I get the following result:
Code:
sed: command garbled: s_export PATH=/usr/bin:/usr/sbin_export PATH=/usr/bin:/usr/sbin:/usr/jdk/jdk1.8.0_60_g

Is there anyone out there that can help me Smilie

Herbie

Last edited by Scrutinizer; 04-09-2016 at 06:58 AM.. Reason: code tags
# 2  
Old 04-09-2016
You need to use a different RE delimiter, because _ also occurs in the replacement string. Instead of _ try |
Code:
sed 's|export PATH=/usr/bin:/usr/sbin|export PATH=/usr/bin:/usr/sbin:/usr/jdk/jdk1.8.0_60|g' .profile

or
Code:
sed 's|export PATH=/usr/bin:/usr/sbin|&:/usr/jdk/jdk1.8.0_60|g' .profile

or perhaps even
Code:
sed 's|export PATH=.*|&:/usr/jdk/jdk1.8.0_60|g' .profile

# 3  
Old 04-09-2016
Too late Smilie

Hi,
Your problem is your character's choice '_' in s command, because jdk1.8.0_60 containt '_'.

Regards.
# 4  
Old 04-09-2016
Quote:
Originally Posted by Scrutinizer
You need to use a different RE delimiter, because _ also occurs in the replacement string. Instead of _ try |
Code:
sed 's|export PATH=/usr/bin:/usr/sbin|export PATH=/usr/bin:/usr/sbin:/usr/jdk/jdk1.8.0_60|g' .profile

or
Code:
sed 's|export PATH=/usr/bin:/usr/sbin|&:/usr/jdk/jdk1.8.0_60|g' .profile

or perhaps even
Code:
sed 's|export PATH=.*|&:/usr/jdk/jdk1.8.0_60|g' .profile

I think a typo sneaked into the replacements... There isn't any need for a global substitution here. I think you meant:
Code:
sed 's|export PATH=/usr/bin:/usr/sbin|export PATH=/usr/bin:/usr/sbin:/usr/jdk/jdk1.8.0_60_g|' .profile

or
Code:
sed 's|export PATH=/usr/bin:/usr/sbin|&:/usr/jdk/jdk1.8.0_60_g|' .profile

or
Code:
sed 's|export PATH=.*|&:/usr/jdk/jdk1.8.0_60_g|' .profile

This User Gave Thanks to Don Cragun For This Post:
# 5  
Old 04-09-2016
Ah yes, so it did, absolutely correct Smilie !

-- edit --

Hold on actually, I think it should be:

Code:
sed 's|export PATH=/usr/bin:/usr/sbin|export PATH=/usr/bin:/usr/sbin:/usr/jdk/jdk1.8.0_60|' .profile

or
Code:
sed 's|export PATH=/usr/bin:/usr/sbin|&:/usr/jdk/jdk1.8.0_60|' .profile

or perhaps even
Code:
sed 's|export PATH=.*|&:/usr/jdk/jdk1.8.0_60|' .profile

This User Gave Thanks to Scrutinizer For This Post:
# 6  
Old 04-09-2016
Ah, yes. Scrutinizer just copied the unneeded g flag from hvdalsen's initial code.

Sorry for the confusion.

- Don
# 7  
Old 04-10-2016
You probably want to save your changes, and mayhap back to the original file? Make it
Code:
sed '...' .profile  >TMP && mv TMP  .profile

, then.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Adding a comma at the end

Hallo Team, I have a big file and the sample looks like below: 0105550 0105550 0105550 0105550 0105550 0125550 0125550 0125550 0125550 0125550 0215650 0215650 0215650 0215650 0215650 0315550 (3 Replies)
Discussion started by: kekanap
3 Replies

2. UNIX for Dummies Questions & Answers

profile PATH include subdirectories

I would like to modify my .profile PATH to include all subdirectories of the directory I specify. For example, right now I have PATH=$HOME/tier1 Tier1 has a tier2 directory in it. Right now I can execute files from tier1, but not tier2. I know I can add another path with $HOME/tier1/tier2,... (1 Reply)
Discussion started by: Smed
1 Replies

3. UNIX for Dummies Questions & Answers

echo $PATH doesn't match $HOME/.profile

This is on a Solaris 9 box, but I feel like a noob, so I am posting here. When I echo $PATH I get a lot of duplicate paths and extra stuff I don't need. What I want is just what I set up in my home dir under .profile My login shell=/bin/bash I checked the following and there are no path... (1 Reply)
Discussion started by: Veestan
1 Replies

4. UNIX for Dummies Questions & Answers

full path of .profile in unix

need a help, am a newbe in unix how do i locate the full path of the .profile where the environmental variable for a user is set. thanks (6 Replies)
Discussion started by: dba
6 Replies

5. UNIX for Dummies Questions & Answers

adding PATH variable

Hello i use bash and i added a path variable for 2 files /rscr and /uscr in /etc/profile /rscr working fine but the other one shows command not found and when i try to type whereis for scripts in /rscr it shows them but the other one shows nothing... thanks :b: (3 Replies)
Discussion started by: wir3d
3 Replies

6. UNIX for Dummies Questions & Answers

Edited Path in Profile File

Definitely a unix dummy. I edited the paths in the /etc/profile file - following the instructions on an install package. Now can't use vi, cat pg ls or any other unix commands. Guess I'm in big trouble. Path reads MANPATH=/opt/hpnp/man PATH=/opt/hpnpl/bin LD_LIBRARY_PATH=/opt/hpnp/lib ... (4 Replies)
Discussion started by: thewetch
4 Replies

7. UNIX for Dummies Questions & Answers

adding a column at the end of the record

hello., i have a .txt file. inside the .txt file i have., /home/ss/cca.costco.transaction_date /home/sk/cca.costco.transaction_date /home/st/cca.costco.transaction_date /home/sv/cca.costco.transaction_date cca.costco.transaction_date is the file name. inside the file there are some... (2 Replies)
Discussion started by: pavan_test
2 Replies

8. Shell Programming and Scripting

taking the end off a path

I need a script to be able to take a path such as "/foo/bar/thing" a put the "/foo/bar/" bit in one variable and the "thing" bit in another. I figured awk would probably be the best tool for the job but looking at the man page didn't seem to help. The only way i know how to use awk is with... (12 Replies)
Discussion started by: Nat
12 Replies

9. UNIX for Dummies Questions & Answers

Modifying $PATH variable in /etc/profile

In my /etc/profile, my $PATH variable is set as follows: $PATH =/sbin:/usr/sbin:/usr/bin:/etc Then how do I add an additional directory to it? say /export/home/abd/rose Please advise. Thanks! Deepali (3 Replies)
Discussion started by: Deepali
3 Replies
Login or Register to Ask a Question