current dir from .command scripts

Scot Hacker shacker at birdhouse.org
Fri Aug 3 10:49:31 PDT 2007


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?

Thanks,
Scot
  


More information about the MacOSX-talk mailing list