LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   using $PATH with whereis (https://www.linuxquestions.org/questions/programming-9/using-%24path-with-whereis-363798/)

shanenin 09-15-2005 09:51 PM

using $PATH with whereis
 
I notice the whereis command does not use your $PATH variable. In particular it did not find the location of kate. So I decided to try and write an alisas that uses your $PATH variable. this code works
Code:

shane@mainbox ~ $ whereis -B {/usr,/usr/bin,/usr/kde/3.4/bin} -f kate
kate: /usr/kde/3.4/bin/kate

I would think this would also work, but it does not
Code:

shane@mainbox ~ $ whereis -B {`echo $PATH | tr ":" ","`} -f kate
kate:

what am I doing wrong

I would think the above code would expand to this, which does work
Code:

shane@mainbox ~ $ whereis -B {/bin,/usr/bin,/usr/local/bin,/opt/bin,/usr/i686-pc-linux-gnu/gcc-bin/3.3.5-20050130,/usr/i386-pc-linux-gnu/gcc-bin/3.3.5,/opt/sun-jdk-1.4.2.08/bin,/opt/sun-jdk-1.4.2.08/jre/bin,/opt/sun-jdk-1.4.2.08/jre/javaws,/usr/qt/3/bin,/usr/kde/3.4/bin,/usr/kde/3.3/bin,/usr/games/bin,/home/shane/bin} -f kate
kate: /usr/kde/3.4/bin/kate /usr/kde/3.3/bin/kate


jlliagre 09-16-2005 02:01 AM

try
Code:

whereis -B $(echo $PATH| tr ':' ' ')  -f kate

shanenin 09-16-2005 08:24 AM

thanks that works :-)

do you have an explanation why this works(using braces)
Code:

whereis -B {/usr,/usr/bin,/usr/kde/3.4/bin} -f kate
but the following methed using braces does not
Code:

shane@mainbox ~ $ whereis -B {$(echo $PATH | tr ':' ',')} -f kate
kate:


shanenin 09-16-2005 08:39 AM

now I understand why your method works, because items in commas and braces expand with spaces
Code:

shane@mainbox ~ $ echo {dfg,jjk}
dfg jjk

but when I do command substitution in braces it does not expand the same way
Code:

shane@mainbox ~ $ echo {$(echo dfg,ghh)}
dfg,ghh


jlliagre 09-16-2005 09:15 AM

Yes, this is a bash specific brace expansion feature, e.g.:
Code:

a{d,c,b}e
expands to
Code:

ade ace abe

shanenin 09-16-2005 09:28 AM

I wonder of the maintainers of bash left out being able to use comand subtitution in braces for a specific reason(refering to my failed code).

I also noticed this a few days ago
Code:

shane@mainbox ~ $ echo t{yh}
t{yh}

I would expect that to return tyh, but it dos not. According to bash you need at least two items seperated by commas for the properties of braces to work.


All times are GMT -5. The time now is 04:41 PM.