current dir from .command scripts

David P. Henderson dp.chaoswerks at gmail.com
Fri Aug 3 11:32:47 PDT 2007


On 03 Aug 2007, at 13:49, Scot Hacker wrote:

> I'm working on a shell script that will be double-clickable, using  
> the "rename with .command extension" trick. I've hit a snag --  
> can't seem to get  the current working directory. Try this:
>
> #!/bin/sh
> basedir=$(pwd)
> echo $basedir
>
> Save  this as test.command onto the Desktop (or anywhere  but your  
> home). Run it from the  Terminal, you get, e.g. :
> /Users/yourname/Desktop
>
> Now, instead  of running it from Terminal,  double click it in   
> Finder.  You get:
> /Users/yourname
>
> So it seems like double-clicked  shell  scripts  aren't  able  to   
> determine  the actual current working directory. Anyone know of a  
> workaround for  this?
>
In a GUI what is the current working directory? ~/ seems reasonable  
or should it be the frontmost window? the desktop? the directory in  
from which the app was launched? Current working directory perhaps  
lacks meaning in a GUI metaphor, meaning which exists in a shell. Or  
maybe the current working directory in a GUI, at least on Mac OS X,  
should always be the desktop?

I think you need to redefine what exactly you are attempting to  
accomplish and determine how to do that.

Dave
--
Chaoswerks Design
"Beautiful bodies and beautiful personalities rarely go together."
     - Carl Jung




More information about the MacOSX-talk mailing list