1

This question is regarding dollar signs "$" $ in Windows PowerShell ISE.

I have PHP CLI and want to run one liner command scripts from the prompt in Windows PowerShell ISE.

php -r "$foo = 'foo';"

Just returns Parse error: parse error in Command line code on line 1 and I've narrowed it down to the pesky dollar sign which is significant in PowerShell. Can I escape it somehow?

I also tried

php -r '$foo = "foo";'

and get

Notice: Use of undefined constant foo - assumed 'foo' in Command line code on line 1

0

2 Answers 2

2

Yes, add a backtick in front of the dollar sign:

php -r "`$foo = 'foo';"
Sign up to request clarification or add additional context in comments.

1 Comment

Also, I don't know if single-quotes are significant in PHP, but if OP encloses the command in single-quotes (and used double-quotes around foo), then there wouldn't be a need to escape the $ as Powershell interprets anything in single-quotes literally.
1

This is what you need:

"`$foo = 'foo';"

2 Comments

Thank you, I found it right after I posted :) I should have just searched a bit longer, but SO welcomes new content anyway.
I will. you know it doesn't allow that for a few minutes :p

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.