Operating System - HP-UX
1829703 Members
2004 Online
109992 Solutions
New Discussion

Re: Appending text to the end of line one in /etc/PATH

 
Neil Herring_1
Advisor

Appending text to the end of line one in /etc/PATH

I need to add a path variable to all my servers and would like to send out the text "/usr/local/bin" and have this added to the end of the line in /etc/PATH.

I have no idea how this might be achieved as sed seems a bit limited for the task.
6 REPLIES 6
harry d brown jr
Honored Contributor

Re: Appending text to the end of line one in /etc/PATH

vi

or

echo ":NEWPATH" >> /etc/PATH

This is truely extremely BASIC stuff.

live free or die
harry d brown jr
Live Free or Die
Pete Randall
Outstanding Contributor

Re: Appending text to the end of line one in /etc/PATH

echo `head -1 /etc/PATH`":/usr/local/bin" > /etc/PATH


Pete

Pete
Pete Randall
Outstanding Contributor

Re: Appending text to the end of line one in /etc/PATH

And, by the way, I expect (and, in fact, would hope) your /etc/PATH only has one line in it, so Harry's solution is even simpler.


Pete

Pete
Neil Herring_1
Advisor

Re: Appending text to the end of line one in /etc/PATH

Thanks Peter

It was the "head -1" command that I was missing. A simple "echo :/usr/local/bin" into the /etc/PATH just adds it as a 2nd line, which was my problem as I wanted it appended to line 1.

Cheers muchly

Neil
harry d brown jr
Honored Contributor

Re: Appending text to the end of line one in /etc/PATH

I think the "head" option is better because most /etc/PATH files have a NEWLINE at the end, thus an append won't work unless that NEWLINE is stripped out.

Oh well.

live free or die
harry d brown jr
Live Free or Die
Neil Herring_1
Advisor

Re: Appending text to the end of line one in /etc/PATH

Thanks to Peter

I now have a solution

Great stuff.

Cheers