0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【Mac】CLIでURLエンコードする方法

Last updated at Posted at 2025-10-23

jqを使う方法

$ echo -n "テスト" | jq -sRr '@uri'
%E3%83%86%E3%82%B9%E3%83%88
  • -s (slurp): 入力全体を1つの文字列として読み込む
  • -R (raw-input): 入力をJSON文字列ではなく生のテキストとして扱う
  • -r (raw-output): 出力時にJSONの引用符を削除
  • @uri: URLエンコード用のフォーマット関数

jqのインストール

jqは以下のコマンドでインストールできます。

brew install jq

Pythonを使う方法

$ echo "テスト" | python3 -c "import sys, urllib.parse; print(urllib.parse.quote(sys.stdin.read().strip()))"
%E3%83%86%E3%82%B9%E3%83%88
0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?