LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices

Reply
 
LinkBack Search this Thread
Old 08-05-2004, 05:11 AM   #1
melinda_sayang
Member
 
Registered: Dec 2003
Location: Petaling Jaya
Distribution: Ubuntu
Posts: 475

Rep: Reputation: 31
how do I remove a variable from PATH


export PATH=$PATH:/blablabla/blablabla

Now, how do I remove /blablabla/blablabla from $PATH environment variable?
Thank you.
 
Old 08-05-2004, 06:08 AM   #2
gbonvehi
Senior Member
 
Registered: Jun 2004
Location: Argentina (SR, LP)
Distribution: Slackware
Posts: 3,145

Rep: Reputation: 51
You have to set the variable again, of course, you have to make a script to remove that piece from it and then set it again.
 
Old 08-05-2004, 06:51 AM   #3
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
PATH=$(echo "$PATH" | sed 's/:/\n/g' | grep -vFx "/blablabla/blablabla" | awk '{ORS=":";print $0}' | sed 's/:$//')

Yves.
 
Old 08-05-2004, 07:50 AM   #4
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
or :
PATH=$(echo $PATH | perl -pe 's/\/blabla\/blabla:?//')

Last edited by Cedrik; 08-05-2004 at 07:52 AM.
 
Old 08-05-2004, 08:11 AM   #5
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
You're right, Cedrik.

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.
 
Old 08-05-2004, 08:22 AM   #6
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
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 :

Code:
PATH=$(echo $PATH | perl -ne '@s=split /:/,$_;while(@s){$b=shift @s;unless($b=~/^\/bin$/){print "$b:";}}')

Last edited by Cedrik; 08-05-2004 at 08:46 AM.
 
Old 08-05-2004, 11:01 AM   #7
melinda_sayang
Member
 
Registered: Dec 2003
Location: Petaling Jaya
Distribution: Ubuntu
Posts: 475

Original Poster
Rep: Reputation: 31
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.

Thank you.
 
Old 08-05-2004, 11:07 AM   #8
Cedrik
Senior Member
 
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140

Rep: Reputation: 242Reputation: 242Reputation: 242
Code:
# to replace /mnt/gudang/NWN/program/jdk1.5.0/bin
# by /usr/lib/java/bin
# try :

PATH=$(echo $PATH | perl -pe 's#/mnt/gudang/NWN/program/jdk1.5.0/bin#/usr/lib/java/bin#')
export PATH

# to replace /usr/lib/java/bin
# by /mnt/gudang/NWN/program/jdk1.5.0/bin
# try :

PATH=$(echo $PATH | perl -pe 's#/usr/lib/java/bin#/mnt/gudang/NWN/program/jdk1.5.0/bin#')
export PATH

Last edited by Cedrik; 08-05-2004 at 11:13 AM.
 
Old 08-06-2004, 03:28 AM   #9
theYinYeti
Senior Member
 
Registered: Jul 2004
Location: France
Distribution: Arch Linux
Posts: 1,897

Rep: Reputation: 61
Quote:
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.

Yves.
 
Old 08-06-2004, 04:56 AM   #10
melinda_sayang
Member
 
Registered: Dec 2003
Location: Petaling Jaya
Distribution: Ubuntu
Posts: 475

Original Poster
Rep: Reputation: 31
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.
 
Old 02-27-2009, 02:45 PM   #11
crackpipe
Member
 
Registered: Nov 2005
Distribution: Slackware, Zenwalk, Debian
Posts: 33

Rep: Reputation: 15
Um, wouldn't it just be easier to remove it from your "etc/profile" file?
 
Old 02-27-2009, 02:52 PM   #12
Alien Bob
Slackware Contributor
 
Registered: Sep 2005
Location: Eindhoven, The Netherlands
Distribution: Slackware
Posts: 5,111

Rep: Reputation: Disabled
What's this sudden influx of newbies trying to revive the corpses of dead threads? This one is nearly 5 years old!

Eric
 
Old 02-27-2009, 04:24 PM   #13
brianL
LQ 5k Club
 
Registered: Jan 2006
Location: Oldham, Lancs, England
Distribution: Slackware & Slackware64 14.1
Posts: 6,688
Blog Entries: 51

Rep: Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238Reputation: 1238
Yes, there's a plague of zombie threads, Eric. Be afraid...be very afraid.
 
Old 02-27-2009, 09:13 PM   #14
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 10,882
Blog Entries: 1

Rep: Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307Reputation: 1307
Hi,

Yes, We can!

Shucks, wrong forum.
 
Old 02-27-2009, 09:33 PM   #15
bgeddy
Senior Member
 
Registered: Sep 2006
Location: Liverpool - England
Distribution: slackware64 13.37 and -current, Dragonfly BSD
Posts: 1,810

Rep: Reputation: 227Reputation: 227Reputation: 227
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PATH variable jk21 Linux - Newbie 1 09-28-2004 02:48 PM
$path variable ? moby Linux - Newbie 3 06-01-2004 03:18 PM
the path variable mjkramer Linux - Newbie 4 10-18-2003 07:18 AM
PATH variable file pongsu Linux - General 2 09-25-2003 04:13 AM
how to remove PATH variable? greg108 Linux - Newbie 2 08-22-2003 01:55 PM


All times are GMT -5. The time now is 03:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration