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.)

3
  • 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, 2013 at 10:18
  • So, in other words you can't get what you want ;-)
    – Havelock
    Sep 11, 2013 at 10:27
  • But I do get what I want on another box with php 5.3...
    – the
    Sep 11, 2013 at 11:03

2 Answers 2

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 ...

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__);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.