1

How would you get the string output of the current shell in PHP?

This is what I tried

$output = shell_exec('echo $SHELL 2>&1');

but I'm getting empty output when I print it out.

$output should be a string that is something like /bin/bash

7
  • Possible duplicate of shell_exec() returning null on "ls" Commented Apr 28, 2017 at 22:15
  • 1
    The code above produces no errors for me and runs just fine, returning the value I expect. I'd suggest simplifying the script include just this line along with the opening php tag and checking out the error log to see if something else failed in php which might cause nothing to be output. Commented Apr 28, 2017 at 22:21
  • 1
    @l'L'l the only (visible) anwser on that question says to add 2>&1 to the command, which OP already has. It is not a duplicate for that question. Commented Apr 28, 2017 at 22:22
  • @JonathanKuhn: The permissions were more of what might be worth focusing on... Commented Apr 28, 2017 at 22:34
  • @user3226932: Do other commands return output normally? Commented Apr 28, 2017 at 22:37

1 Answer 1

1

There is an specific function for getting environment variable values that you can use: getenv():

echo getenv('SHELL');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.