Welcome to new things

[Technical] [Electronic work] [Gadget] [Game] memo writing

How to encode and decode URLs with shell scripts

This is a memo on how to encode and decode URLs with shell scripts.

You can find many ways to do this by searching.

At first, we tried using nkf for both encoding and decoding, but the encoding did not work for long sentences, so we decided to use jq for encoding.

URL encoding/decoding method

So far, the following examples are operating without problems.

#!/bin/bash

str="AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
echo $str

encode=$(echo $str | jq -Rr '@uri')
echo $encode

decode=$(echo $encode | nkf -w --url-input)
echo $decode

Impressions, etc.

I'm concerned that if it's a combination of commands that you've implemented, it's not really right.

Although jq and nkf need to be installed separately, we decided to use them this time because the options are implemented for URL encoding and decoding.

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com

www.ekwbtblog.com