0

I am currently debugging some code and I am getting an error of: ls: invalid option -- '/'. However if I try the value for $somePath in terminal it gives me the result. Why am I getting the error?

PHP:

exec('ls -A' . $somePath.' | grep .', $output);

Terminal Path:

ls -A /home/userName/public_html/path/folder

1 Answer 1

1

Probably you meant:

exec('ls -A ' . $somePath . ' | grep .', $output);
// SPACE --^

When getopt parses options starting with '-' but not with '--', it treats each character as an another option. It thought you passed options: 'A', '/', 'h', 'o', ... It just does not accept '/' character.

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.