>>> On Sat, Apr 14, 2007 at 10:54 AM, in message <[EMAIL PROTECTED]>, "McKown, John" <[EMAIL PROTECTED]> wrote: >> -----Original Message----- >> From: Linux on 390 Port [mailto:[EMAIL PROTECTED] On >> Behalf Of Leland Lucius >> Sent: Friday, April 13, 2007 4:17 PM >> To: [email protected] >> Subject: Re: How to replace a "entry" in PATH? >> >> Quoting "McKown, John" <[EMAIL PROTECTED]>: >> >> > #!/bin/sh >> > newhome="/java160" >> > if [ ! -z "$JAVA_HOME" ]; then >> > PATH=$(echo "$PATH" | sed -e "s#$JAVA_HOME/bin##g;s/::/:/g") >> > fi >> > export JAVA_HOME=${newhome} >> > export PATH="$PATH:$JAVA_HOME/bin" >> > >> Will this work for ya? >> >> Leland > > That looks promising. I would think that the # symbol is not likely to > occur in a directory name.
Which is exactly the point. Slashes do show up in the PATH, so if you used the default sed syntax, you would have to do something like this: sed -e "s/$JAVA_HOME\/bin//g;s/::/:/g" By using a delimiter character that won't be in the string, you don't have to escape that character when you use it in the string. The way sed works, you can use just about any delimiter character: sed -e "s%$JAVA_HOME/bin%%g;s%::%:%g" In this particular case, just escaping one "/" may not have been worth the change. If you have a lot of instances in the string, it can be a real time saver and readability enhancer. Mark Post ---------------------------------------------------------------------- For LINUX-390 subscribe / signoff / archive access instructions, send email to [EMAIL PROTECTED] with the message: INFO LINUX-390 or visit http://www.marist.edu/htbin/wlvindex?LINUX-390
