LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   regex in paths (https://www.linuxquestions.org/questions/linux-newbie-8/regex-in-paths-333787/)

basher400 06-15-2005 06:02 AM

regex in paths
 
hi

i'm trying to get a certain part of the path into a var.

lets say I have the following path:
/usr1/web/java/A55771/

the "/usr1/web/java/" part will always be the same, what I am looking for is the "A55771" part. (this part might be "B66-154-89" in a different case)
so I did this:

Code:

PATH="/usr1/web/java/A55771/"
BASE="/usr1/web/java/"
MYDIR=`$PATH | sed s/"$BASE"//g`

MYDIR should hold "A55771/".

what am I doing wrong?

perfect_circle 06-15-2005 06:48 AM

Code:

skalkoto@darkstar:~$ a="/usr1/web/java/A55771/"
skalkoto@darkstar:~$ b="/usr1/web/java/"
skalkoto@darkstar:~$ c="${a#$(echo $b)}"
skalkoto@darkstar:~$ echo $c
A55771/
skalkoto@darkstar:~$


basher400 06-15-2005 07:06 AM

Quote:

Originally posted by perfect_circle
Code:

skalkoto@darkstar:~$ a="/usr1/web/java/A55771/"
skalkoto@darkstar:~$ b="/usr1/web/java/"
skalkoto@darkstar:~$ c="${a#$(echo $b)}"
skalkoto@darkstar:~$ echo $c
A55771/
skalkoto@darkstar:~$


thanks :)

jonaskoelker 06-15-2005 07:08 AM

Quote:

what am I doing wrong?
MYDIR=`echo $PATH | sed s/"$BASE"//g`

And you may want to not use PATH if you don't know the function of the PATH variable in general (read the bash manual).

hth --Jonas


All times are GMT -5. The time now is 01:37 AM.