Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > Bash (or maybe ls) difference between linux/osx --anyone seen this ?

Bash (or maybe ls) difference between linux/osx --anyone seen this ?
Thread Tools
Fresh-Faced Recruit
Join Date: Apr 2003
Status: Offline
Reply With Quote
Jul 8, 2003, 07:20 PM
 
Folks,

This is driving me crazy.

First up, my linux box:

root@monster:# echo $BASH_VERSION
2.05.0(1)-release

root@monster:# ls $(which javac)
/usr/local/packages/jdk/bin/javac

Note carefully, now I want to see all
entries in the same directory where
javac resides:

root@monster:# ls $(dirname $(which javac))
ControlPanel jar javadoc kinit policytool servertool
HtmlConverter jarsigner javah klist rmic tnameserv
appletviewer java javap ktab rmid
extcheck java-rmi.cgi jdb native2ascii rmiregistry
idlj javac keytool orbd serialver


Now on Mac OSX:

bash-2.05a# echo $BASH_VERSION
2.05a.0(1)-release

bash-2.05a# ls $(which javac)
/usr/bin/javac

Note, very carefully, /usr/bin/javac is actually a link:

bash-2.05a# ls -l $(which javac)
lrwxr-xr-x 1 root wheel 58 Jul 8 19:29 /usr/bin/javac -> /System/Library/Frameworks/JavaVM.framework/Commands/javac

Now suppose I want to see other files in the same directory as where /usr/bin/javac points to.

Try 1)
bash-2.05a# ls $(dirname $(which javac))

Well, this gives me the files in
/usr/bin and not:
/System/Library../Commands

Try 2)
After reading the ls man page, it seems
that I have to specify the -L flag
to force 'ls' to follow the link.

---quote from 'man ls'--

-L If argument is a symbolic link,
list the file or directory the
link references rather than the
link itself.
-----end quote---------

Well, let's try this:

bash-2.05a# ls -L $(which javac)
/usr/bin/javac

Dammit. This really sucks. The "-L"
flag of 'ls' does not work. This means
I cannot do on my OSX box what I can
easily do on my linux box. So for
example, the following does NOT work:

bash-2.05a#
ls $(dirname $(ls -L $(which javac)))

(still shows me files in /usr/bin)

Any suggestions or comments (of course
there are ways around this, whereby
I can simply do "ls /Library/Java/Home"
but that's a hack. The correct elegant
way to do this is to use "which" but
that doesn't work..

Best regards,

--j
     
Fresh-Faced Recruit
Join Date: Apr 2003
Status: Offline
Reply With Quote
Jul 8, 2003, 07:35 PM
 
Ok. Followup to my own post earlier.

Turns out that "ls -L" is _not_ broken on OSX.

To wit, if I do on my linux box:

root@monster:/tmp# ln -s $(which java) j
root@monster:/tmp# ls -L j
j
root@monster:/tmp#

This means that ls -L does not follow the link even on linux. I guess I am confused about what it does. The original questions still stands: how do I list all files in the same directory as "java" using $(which java) to find the java executable ?

--j
     
Dedicated MacNNer
Join Date: Jul 2001
Location: NC
Status: Offline
Reply With Quote
Jul 12, 2003, 11:38 PM
 
   A good man page (I have seen them) correctly explains that -L causes ls to provide the information for target of a symlink but not the name. Every system does have a mechanism for displaying the target but it varies from system to system. On OpenBSD and MacOS X the utility is readlink. Thus what you want can be accomplished in a Bourne type shell with:

ls $(dirname $(readlink $(which java)))
Gary
A computer scientist is someone who, when told to "Go to Hell", sees the
"go to", rather than the destination, as harmful.
     
Senior User
Join Date: Jan 2001
Location: Mahwah, NJ USA
Status: Offline
Reply With Quote
Jul 13, 2003, 11:50 AM
 
Originally posted by javadesigner:
Ok. Followup to my own post earlier.

Turns out that "ls -L" is _not_ broken on OSX.

To wit, if I do on my linux box:

root@monster:/tmp# ln -s $(which java) j
root@monster:/tmp# ls -L j
j
root@monster:/tmp#

This means that ls -L does not follow the link even on linux. I guess I am confused about what it does. The original questions still stands: how do I list all files in the same directory as "java" using $(which java) to find the java executable ?

--j
Didn't you mean to do?:

root@monster:/tmp# ln -s $(dirname $(which java)) j

In which case an:

root@monster:/tmp# ls -L j

will return the contents of the directory that java resides in.
-DU-...etc...
     
Fresh-Faced Recruit
Join Date: Apr 2003
Status: Offline
Reply With Quote
Jul 15, 2003, 06:22 PM
 
Didn't you mean to do?:

root@monster:/tmp# ln -s $(dirname $(which java)) j

In which case an:

root@monster:/tmp# ls -L j

will return the contents of the directory that java resides in.
Yup, good catch. That does work on linux. But it doesn't work on mac osx though...
     
Fresh-Faced Recruit
Join Date: Apr 2003
Status: Offline
Reply With Quote
Jul 15, 2003, 06:27 PM
 
I don't get.


First:
root@hmac:/tmp# ls -l /usr/bin/java
lrwxr-xr-x 1 root wheel 57 Jul 15 12:40
/usr/bin/java ->
/System/Library/Frameworks/JavaVM.framework/Commands/java

Second:
root@hmac:/tmp# ls -L /usr/bin/java
/usr/bin/java


from ls man page (manual page on Mac OS X 10.2):
-------
-L If argument is a symbolic link, list the file or directory the
link references rather than the link itself.
------

I don't get it. ls -L should have shown the target (when I
typed the second command) but it doesn't.
     
   
Thread Tools
Forum Links
Forum 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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:02 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2