Edit: You want something completely different than my original answer. Keeping it below in case it is useful to anyone. Now I think you are looking for the basename
command, although I'm still not certain and I think you'll need to specify more information about what you are doing before we'll be able to give you a decent answer.
I'm not sure I understand the question. Are you trying to locate the application directory? E.g. for Calculator, you want the directory that Calculator.app is in?
jed@jed-osx:~$ ls -la /Applications/Calculator.app/
total 0
drwxr-xr-x 3 root wheel 102 Jun 22 11:27 .
drwxrwxr-x+ 46 root admin 1564 Jun 18 23:19 ..
drwxr-xr-x 10 root wheel 340 Jun 22 11:26 Contents
jed@jed-osx:~$ ls -la /Applications/Calculator.app/Contents/
total 8
drwxr-xr-x 10 root wheel 340 Jun 22 11:26 .
drwxr-xr-x 3 root wheel 102 Jun 22 11:27 ..
lrwxr-xr-x 1 root wheel 28 Apr 17 15:15 CodeResources -> _CodeSignature/CodeResources
-rw-r--r-- 1 root wheel 1201 May 6 10:26 Info.plist
drwxr-xr-x 3 root wheel 102 Jun 22 11:26 MacOS
-rw-r--r-- 1 root wheel 8 Jul 6 2009 PkgInfo
drwxr-xr-x 4 root wheel 136 Jul 6 2009 PlugIns
drwxr-xr-x 42 root wheel 1428 Apr 17 15:28 Resources
drwxr-xr-x 3 root wheel 102 Jun 22 11:26 _CodeSignature
-rw-r--r-- 1 root wheel 451 May 6 10:27 version.plist
Or are you looking for something completely different?
1Does the shell script belong to the app resources? Anyway, this question belongs to Stackoverflow. – mouviciel – 2010-06-24T11:20:15.287
In my case, the shell script IS the App's executable. – moala – 2010-06-24T13:09:14.000
I've always wanted to know if/how I could do this. – Jeremy Banks – 2010-08-14T04:49:47.387