On PHP, how to exit or quit form "php -r '<something>'" when ">" keeps appearing in the terminal?

Viewed 88

I'm trapped by php -r and can't escape from the ">".


I tried to run a simple PHP command from the terminal. Which was $ php -r '<the PHP commands>', so to see what the results would be.

But something went wrong and the terminal keeps showing me the ">" console. Whatever I type gives me nothing but ">". Even ^C (control+C) nor Command+q didn't exit/escape/quit from the situation.

The commands supposed to be something like so:

php -r '$url_img_source="[here URL]"; echo serialize(file_get_contents($url_img_source));'

Since the URL was too long to type, after typing php -r '$url_img_source=, I copied and pasted it.

But 2 things I failed.

  1. The copied string was quoted with a single quotation instead of double.
  2. The copied string contained a line break (Enter) at the end.

Therefore, as soon as I pasted it, it started to run. Before finishing the script. I always do things like this and this time I've been trapped ...

$ php -r '$url_img_source='https://upload.wikimedia.org/wikipedia/commons/a/a8/%E3%83%87%E3%83%BC%E3%82%BF%E3%82%AB%E3%83%BC%E3%83%89%E3%83%80%E3%82%B9_%E4%BB%AE%E9%9D%A2%E3%83%A9%E3%82%A4%E3%83%80%E3%83%BC%E3%82%AC%E3%83%B3%E3%83%90%E3%83%A9%E3%82%A4%E3%82%B8%E3%83%B3%E3%82%B0_%E3%82%AC%E3%82%B7%E3%83%A3%E3%83%83%E3%83%88%E3%83%98%E3%83%B3%E3%82%B7%E3%83%B3_%E5%A4%A7%E3%81%AF%E3%81%A3%E3%81%B4%E3%82%87%E3%81%86%E3%81%8B%E3%81%84_%28%E3%82%B4%E3%83%BC%E2%98%86%E3%82%B8%E3%83%A3%E3%82%B9%29_22m30s.jpg';

>
> q
> quit
> quit()
> exit
> exit()
> ^C
> bye
>
>
> die
> die()
> :q
> 

I sent a reset and hard reset signal from the terminal too but didn't work. Just cleared the screen and again the ">" showed up.

I could turn down the terminal window. But since I'm running this on Docker PHP7-alpine container over macOS Mojave, and there are other files that haven't saved to local so I am afraid to shut the terminal down by force.

What other choices do I have?

2 Answers
php -r '$url_img_source="https://upload.wikimedia.org/wikipedia/commons/a/a8/%E3%83%87%E3%83%BC%E3%82%BF%E3%82%AB%E3%83%BC%E3%83%89%E3%83%80%E3%82%B9_%E4%BB%AE%E9%9D%A2%E3%83%A9%E3%82%A4%E3%83%80%E3%83%BC%E3%82%AC%E3%83%B3%E3%83%90%E3%83%A9%E3%82%A4%E3%82%B8%E3%83%B3%E3%82%B0_%E3%82%AC%E3%82%B7%E3%83%A3%E3%83%83%E3%83%88%E3%83%98%E3%83%B3%E3%82%B7%E3%83%B3_%E5%A4%A7%E3%81%AF%E3%81%A3%E3%81%B4%E3%82%87%E3%81%86%E3%81%8B%E3%81%84_%28%E3%82%B4%E3%83%BC%E2%98%86%E3%82%B8%E3%83%A3%E3%82%B9%29_22m30s.jpg";';

You are missing the double quotes in your example.

Look, you have: php -r '$url_img_source='https://upload.wikimedi...

It should be: php -r '$url_img_source="..."

3 things you should try to escape from ">"

  1. Try ' and return/enter (@cid's method)
   $ php -r '$url_img_source='https://upload.wikimedia.org/...%22m30s.jpg';

   > '

   Parse error: syntax error, unexpected ':' in Command line code on line 1
   $
  1. Try ctrl-d (@aynber's method)
   $ php -r '$url_img_source='https://upload.wikimedia.org/...%22m30s.jpg';

   > /bin/sh: syntax error: unterminated quoted string
   $
  1. Try ↑ up arrow key to roll back the history and select the same command and run.
   $ php -r '$url_img_source='https://upload.wikimedia.org/...%22m30s.jpg';

   > php -r '$url_img_source='https://upload.wikimedia.org/...%22m30s.jpg';

   Parse error: syntax error, unexpected ':' in Command line code on line 1
   $
Related