urldecode using bash script with live demo – Code Example

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

Open Live Demo