SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
But your solution (equivalent to sed, BTW) has two drawbacks:
- It will "hurt" (don't know the right word), but not remove, the paths that only *contain* the pattern. Example: let's say /bla/bla is /bin; you want to remove /bin from the PATH, then with your method, /usr/bin will become /usr, /usr/X11R6/bin will become /usr/X11R6, and so on (or worse, as the : will surely get removed too).
- It will work for the path you write "by hand", and only this one. And you have to rework the path based on your knowledge of regular expressions. It's OK for running it directly from the prompt, and even then you have to be good at regular expressions. But integration into a script would involve some preparation (with automatic adding of escape characters at the right places), like that:
pathRE=$(echo "$1" | sed -e 's/\./\\./g' -e [...and so on for {}'."/^$...])
PATH=$(echo $PATH | eval perl -pe "'s/"${pathRE}":?//'")
which doesn't help for the first problem anyway.
I hope this helps. I only want to share knowledge. Myself, I didn't know it was so easy to use perl expressions on the command line
Yves.
Last edited by theYinYeti; 08-05-2004 at 08:13 AM.
Well, I didn't think of the /bin remove thing I think you right but note that the perl expression in my post above fails only if you want to remove /bin from the PATH so in practice...
At least thanks for the comment, and point to the exeption.
[edit]
Here is another suggestion that take in account the /bin exeption :
I am sorry. I don't understand. I want to remove /mnt/gudang/NWN/program/jdk1.5.0/bin from PATH environment variable. This is my script.
PATH=$(echo "$PATH" | sed 's/:/\n/g' | grep -vFx "/mnt/gudang/NWN/program/jdk1.5.0/bin" | awk '{ORS=":";print $0}' | sed 's/:$//')
export PATH="/usr/lib/java/bin":"{$PATH}"
I use java 1.5 as default. But sometimes I want to use java 1.4.2. Java 1.5 is in /mnt/gudang/NWN/program/jdk1.5.0/bin and java 1.4.2 is in /usr/lib/java/bin. That script does not work. Please make it clearer.
I don't understand [...] This is my script.
PATH=$(echo "$PATH" | sed 's/:/\n/g' | grep -vFx "/mnt/gudang/NWN/program/jdk1.5.0/bin" | awk '{ORS=":";print $0}' | sed 's/:$//')
export PATH="/usr/lib/java/bin":"{$PATH}"
Last line should be:
export PATH=/usr/lib/java/bin:${PATH}
But then if you make a script, you'd rather make that: useJava.sh
Code:
#!/bin/bash
# Use the java version given by $1 (eg: 142 or 150)
# Here you put the versions that are installed:
MYJAVA142=/usr/lib/java
MYJAVA15=/mnt/gudang/NWN/program/jdk1.5.0
# go!
JAVA_HOME=$(eval echo \"\$MYJAVA$1\")
if [ -z "$JAVA_HOME" ]; then
echo "Version $1 of Java is not installed." >&2
exit 1
fi
JPATHS=$(eval echo -ne \"$(echo "${!MYJAVA*} " | sed 's/\([^ ]*\) /${\1}\\n/g')\" | sed 's|$|/bin|')
PATH=$(echo "$PATH" | sed 's/:/\n/g' | grep -vFx "$JPATHS" | awk '{ORS=":";print $0}' | sed 's/:$//')
PATH=${JAVA_HOME}/bin:${PATH}
export PATH JAVA_HOME
I hope I did not write any mistake. I cannot test what I just wrote.
I don't know what's wrong? This script does not work. I don't understand.
Code:
#!/bin/bash
export PATH=/usr/lib/java/bin:{$PATH}
I run this script thousand times. And yet /usr/lib/java/bin does not included in $PATH. But when I do this command:
export PATH=/usr/lib/java/bin:{$PATH}
or
export PATH=/usr/lib/java/bin:$PATH
I can include /usr/lib/java/bin in $PATH. So is there any wrong with my bash.
Last edited by melinda_sayang; 08-06-2004 at 05:08 AM.
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810
Rep:
This is really starting to bug me. Will all users please not resurrect long dead threads as seems to be happening more and more here. This serves no purpose as the OP will probably have long solved their problem. It just tends to make the forum chaotic and irrelevant - in other words a mess. Lets not turn this place into a joke littered with dredged up crap.
I know I'm guilty of responding to an ancient thread here but this seems to be happening more and more and it's driving me nuts. Please check the post dates before adding to a thread.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.