LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-15-2005, 09:51 PM   #1
shanenin
Member
 
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

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

Last edited by shanenin; 09-16-2005 at 12:35 AM.
 
Old 09-16-2005, 02:01 AM   #2
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
try
Code:
whereis -B $(echo $PATH| tr ':' ' ')  -f kate
 
Old 09-16-2005, 08:24 AM   #3
shanenin
Member
 
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

Original Poster
Rep: Reputation: 30
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:
 
Old 09-16-2005, 08:39 AM   #4
shanenin
Member
 
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

Original Poster
Rep: Reputation: 30
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
 
Old 09-16-2005, 09:15 AM   #5
jlliagre
Moderator
 
Registered: Feb 2004
Location: Outside Paris
Distribution: Solaris 11.4, Oracle Linux, Mint, Debian/WSL
Posts: 9,789

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
Yes, this is a bash specific brace expansion feature, e.g.:
Code:
a{d,c,b}e
expands to
Code:
ade ace abe
 
Old 09-16-2005, 09:28 AM   #6
shanenin
Member
 
Registered: Aug 2003
Location: Rochester, MN, U.S.A
Distribution: Gentoo
Posts: 987

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

Last edited by shanenin; 09-16-2005 at 09:42 AM.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
whereis kate shanenin Linux - Software 4 09-15-2005 02:42 PM
whereis firefox Monjawi Linux - Newbie 1 09-09-2005 05:19 PM
whereis Realplayer? mohapi Fedora 8 06-12-2004 02:00 PM
diffenerce between whereis an which??????? iamthewind Linux - Software 3 10-10-2003 02:01 AM
whereis cups tincat2 Linux - General 2 05-07-2003 11:28 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:10 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration