0

What I want

  • I want to do Google Search from Mac terminal(zsh).
  • The search query includes Japanese Character.

Error

In Mac terminal (zsh), I run this script:

username@usernamenoAir ~ % open -a "Google Chrome" "https://google.co.jp/search?q=東京+天気"

Then, this error occurs:

The file /Users/username/https:/google.co.jp/search?q=東京+天気 does not exist.

What I tried

  • If the query parameter (after q=) only includes alphabet (no Japanese), it works.
username@usernamenoAir ~ % open -a "Google Chrome" "https://google.co.jp/search?q=foo+bar"

% -> ok. Chrome browser launches and returns a search result.
  • Japanese Character works properly in another situation like the following.
username@usernamenoAir ~ % echo 東京
東京

What is wrong? Any information would be appreciated.

Informations

I use zsh 5.8 (x86_64-apple-darwin20.0).

Ulrich Eckhardt
  • 16,572
  • 3
  • 28
  • 55
ten
  • 713
  • 1
  • 3
  • 12
  • You need a way to percent encode characters, that's the keywords to look for. – Larme Jul 03 '23 at 17:30
  • I can't reproduce the issue on my mac but if you use single quotes you get same behavior? (Running a bit newer version, `zsh 5.8.1 (x86_64-apple-darwin22.0)`) – user3783243 Jul 03 '23 at 17:30
  • Why the heck would you tag this with "linux"? – Ulrich Eckhardt Jul 03 '23 at 18:15
  • Rerun `open -a "Google Chrome" "https://google.co.jp/search?q=東京+天気"` and make sure you get the error. Then remove `open -a "Google Chrome"` and run `od -x <<< "https://google.co.jp/search?q=東京+天気"` and post result. – Philippe Jul 03 '23 at 19:25
  • Does this answer your question? [Unicode characters in URLs](https://stackoverflow.com/questions/2742852/unicode-characters-in-urls) – user1934428 Jul 04 '23 at 06:10
  • What version of macOS? It appears the `open` command is failing to recognize the input as a URL; I cannot reproduce this in macOS 13.4. You can try `open -u -a ...` as a workaround. – Gairfowl Jul 04 '23 at 08:25

1 Answers1

0

The query string needs to be URL encoded. Your query string should be converted to UTF-8 then URL encoded, resulting in a URL like this:

https://www.google.co.jp/search?q=%E6%9D%B1%E4%BA%AC+%E5%A4%A9%E6%B0%97
Kurtis Rader
  • 6,734
  • 13
  • 20