How can I encode and decode percent-encoded (URL encoded) strings on the command line?
I'm looking for a solution that can do this:
$ percent-encode "ændrük" %C3%A6ndr%C3%BCk $ percent-decode "%C3%A6ndr%C3%BCk" ændrük
These commands do what you want:
If you want to encode spaces as
I'm guessing you will want to alias them ;-)
Try the following command line:
You may define it as alias and add it to your shell rc files:
Then every time when you need it, simply go with:
When scripting, you can use the following syntax:
However above syntax won't handle pluses (
You can also use the following
bash + xxd
Bash function with
Try to define the following aliases:
Using PHP you can try the following command:
In Perl you can use
Or to process a file:
Try anon solution:
decoding file names
If you need to remove url encoding from the file names, use
I found a package,
Unfortunately, it does not decode stdin or a command line option, but only rename a file, so you have to create a dummy file to obtain the decoding (the name of the renamed file), but with some bash scripting the process can be automated.
No information about the encoding part, even because it could be questionable which characters to encode. Only non-ASCII?
I think there should be some better tool/method.
Pure bash solution for decoding only: