0

~/worsh/worsh.php contains

print getcwd();

Now I do:

cd some-wordpress-site
php ~/worsh/worsh.php

And I get ~/worsh - whereas I obviously want to just get some-wordpress-site.

exec('pwd') has the same result. How do I get what I want?

I should add that it works as expected on one of my hetzner boxes with php 5.3. It doesn't work on my bluehost account with php 5.2. I want it to work everywhere.

(See http://github.com/guaka/worsh for the use case.)

the
  • 21,007
  • 11
  • 68
  • 101
  • The result you're getting is absolutely correct, as this is the *current working dir* of your script. The directory `some-wordpress-site` is the current working dir of your shell program... – Havelock Sep 11 '13 at 10:18
  • So, in other words you can't get what you want ;-) – Havelock Sep 11 '13 at 10:27
  • But I do get what I want on another box with php 5.3... – the Sep 11 '13 at 11:03

2 Answers2

0

Check this related Post -> https://stackoverflow.com/a/17471242/1720166

Additionally check the corresponding PHP Function Doc here: http://php.net/manual/en/function.getcwd.php

... getcwd() returns the path of the "main" script ...

Community
  • 1
  • 1
mazer
  • 171
  • 2
  • 9
0
 echo __DIR__ ; //this is your directory path

the below should get you the last folder, which is what I think you want. So if the path is /var/www/html/some-wordpress-site the below will return some-wordpress-site

echo basename(__DIR__);
Joeme
  • 505
  • 1
  • 5
  • 12