current dir from .command scripts

Mike Galloy mgalloy at gmail.com
Fri Aug 3 11:54:43 PDT 2007


On 8/3/07, Scot Hacker <shacker at birdhouse.org> 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?
>

Try:

echo $0
echo `dirname $0`

in your test.command file. Is one of these what you want?

Mike
--
www.michaelgalloy.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /mailman/archive/macosx-talk/attachments/20070803/b1886813/attachment.html


More information about the MacOSX-talk mailing list