NYCPHP Meetup

NYPHP.org

[nycphp-talk] OS X home directory PHP-CLI

Ron Guerin ron at vnetworx.net
Thu Mar 1 12:37:54 EST 2012


(resent because it never made it back to me)

On 02/22/2012 12:01 AM, Rob Marscher wrote:
>> On Tue, Feb 21, 2012 at 8:19 PM, Ron Guerin <ron at vnetworx.net
>> <mailto:ron at vnetworx.net>> wrote:
>>
>>     I don't have a Mac, and I haven't turned up much useful in Google, so
>>     I'm hoping someone here has written a CLI PHP script for OS X.
>>
>>     I understand that you can't count on HOME to be set.  Is there a
>>     reliable way to find the user's home directory on OS X in PHP?
> 
> On Feb 21, 2012, at 8:26 PM, Federico Ulfo wrote:
>> $home_dir = exec( "cd ~
>>     pwd" );
> 
> FWIW, $_ENV['HOME'] is set on my laptop.
> 
> Here's Federico's technique on one line with backticks:
> 
> $home = `cd ~; pwd`;

I'd read somewhere that scripts launched from the GUI don't necessarily
have HOME set in the environment.   Perhaps that's not true, but I'll go
with one of the suggestions you or Federico made in the event I don't
find HOME.

My thanks to both of you!

- Ron



More information about the talk mailing list