[Code Example] urldecode using bash script with live demo

Total
0
Shares

In this article we will provide you the bash script code to urldecode. This code can decode the percent encoded string like decodeURIComponent() function in javascript.

Code Example –

#!/bin/bash

decodeURIComponent() {
    : "${1//+/ }"
    printf '%b\n' "${_//%/\\x}"
}


decodeURIComponent "https%3A%2F%2Fakashmittal.com%2Fcode-example-urlencode-using-bash-script-with-live-demo%2F"

# Output:
# https://akashmittal.com/code-example-urlencode-using-bash-script-with-live-demo/

Not only urls, this code can decode any kind of percent encoded string.

Inspired from Dylan Araps

Live Demo

Demo might not work in private window (incognito)

Sign Up for Our Newsletters

Get only the best articles delivered to your mail

You May Also Like