Computing.Net > Forums > Unix > Shell script problem

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Shell script problem

Reply to Message Icon

Name: Patrik
Date: January 6, 2003 at 01:54:47 Pacific
OS: Linux
CPU/Ram: Intel/384
Comment:

Hi,

I've a shell script problem. I want to add a string to my PATH variable in .profile.

Regards

Patrik



Sponsored Link
Ads by Google

Response Number 1
Name: David Perry
Date: January 6, 2003 at 02:48:22 Pacific
Reply:

At some point before the line that says

export PATH

declare the following

PATH=$PATH:/new/path/to/add


0

Response Number 2
Name: Patrik
Date: January 6, 2003 at 03:48:01 Pacific
Reply:

Hi,

I know how to add a string to my PATH variable i .profile. I want to do this using a shell script.

/Patrik


0

Response Number 3
Name: David Perry
Date: January 6, 2003 at 04:13:35 Pacific
Reply:

You want to modify /etc/profile in a script?

I would have to see your /etc/profile to give you a solid answer, but you could do it with sed.

#!/bin/sh
if [ `echo $PATH | grep -c 'new_string'` -eq 0 ] ; then
sed -e 's/distinct_string_to_match/\1:new_string/' /etc/profile > /tmp/profile && mv /tmp/profile /etc/profile
fi


0

Response Number 4
Name: Patrik
Date: January 6, 2003 at 05:02:56 Pacific
Reply:

Hi,

My .profile looks like this:

----------

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/java/bin:/usr/local/jre/bin
BASH_ENV=$HOME/.bashrc
USERNAME="root"
ORACLE_HOME=/oracle/product/ora9i

CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib:$ORACLE_HOME/network/jlib:/usr/local/java:/usr/local/jre

export USERNAME BASH_ENV PATH CLASSPATH ORACLE_HOME

-----------

I want to add a string to the PATH variable in a shell script. I've tried with sed, but with no luck.

Regards

Patrik


0

Response Number 5
Name: David Perry
Date: January 6, 2003 at 05:42:57 Pacific
Reply:

So you have a line that begins with PATH. This makes matching easy. Does this make it more clear

sed -e 's,^PATH=$PATH,PATH=$PATH:/new/path,' /etc/profile > /tmp/new-profile

diff /etc/profile /tmp/new-profile


0

Related Posts

See More



Response Number 6
Name: Patrik
Date: January 6, 2003 at 05:55:30 Pacific
Reply:

Thanks, now it's working perfect.

/Patrik


0

Sponsored Link
Ads by Google
Reply to Message Icon

reboot when not loged in ... File .profile



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Shell script problem

korn shell script problem (using awk ? ) www.computing.net/answers/unix/korn-shell-script-problem-using-awk-/3547.html

Squaring Shell Script Problem www.computing.net/answers/unix/squaring-shell-script-problem/5092.html

Shell script problem www.computing.net/answers/unix/shell-script-problem/2479.html