current dir from .command scripts
Macs R We
macsrwe at macsrwe.com
Sat Aug 4 12:13:42 PDT 2007
Sounds to me like you misunderstand what "current working directory"
means. It does not mean the directory in which the application is
located, it means the directory the user is using for his current
base of operations. When you execute the command from the Terminal
it gives the desired results only because you, too, are "sitting at"
the Desktop. But if you "cd" anyplace else and then execute the
command by absolute or relative pathname, you will see that the
result is wherever you have just cd'ed to, and not the Desktop.
All your experiment shows is that the working directory of a user
using the GUI is his home directory.
On Aug 3, 2007, at 12:00 PM, macosx-talk-request at omnigroup.com wrote:
> From: Scot Hacker <shacker at birdhouse.org>
> 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?
--
Macs R We -- Personal Macintosh Service and Support
in the Wickenburg and far Northwest Valley Areas.
http://macsrwe.com
More information about the MacOSX-talk
mailing list