URL Encoding

URL encoding stands for encoding certain characters in a URL by replacing them with one or more character triplets that consist of the percent character "%" followed by two hexadecimal digits. The two hexadecimal digits of the triplet(s) represent the numeric value of the replaced character.

Handy commands to URL encode and decode

echo $(python3 -c "import urllib.parse, sys; print(urllib.parse.quote(sys.argv[1]))" "your input")

Lets create some useful bash functions and add then to your profile

# Change if you are using other python
function urlencode() {
  local input=$1
  echo $(python3 -c "import urllib.parse, sys; 
  print(urllib.parse.quote(sys.argv[1]))" $input)
}

function urldencode() {
  local input=$1
  echo $(python3 -c "import urllib.parse, sys; 
  print(urllib.parse.unquote(sys.argv[1]))" $input)
}

Examples

Useful for Jira Query Language

urldecode "https%3A//jira.oci.oraclecorp.com/issues/%5C%3Fjql%5C%3Dproject%20%3D%20OSCS%20AND%20resolution%20%3D%20Unresolved%20ORDER%20BY%20priority%20DESC%2C%20updated%20DESC"

https://jira.oci.oraclecorp.com/issues/\?jql\=project = OSCS AND resolution = Unresolved ORDER BY priority DESC, updated DESC
urlencode "https://jira.oci.oraclecorp.com/issues/\?jql\=project = OSCS AND resolution = Unresolved ORDER BY priority DESC, updated DESC"

https%3A//jira.oci.oraclecorp.com/issues/%5C%3Fjql%5C%3Dproject%20%3D%20OSCS%20AND%20resolution%20%3D%20Unresolved%20ORDER%20BY%20priority%20DESC%2C%20updated%20DESC