0

According to this answer I wrote a small script to get the decoded output of a text file that has some url encoded strings.

function urldecode() { : "${*//+/ }"; echo -e "${_//%/\\x}"; }
input="temp.txt"
while IFS= read -r line
do
  eval urldecode "$line"
done < "$input"

The problem I found was that while the string foo%20bar was decoded as foo bar, http%3A%2F%2Fwas not decoded. Both of them appear in several lines.

I tried executing single file lines from Terminal and all went good.

  • 1
    Where does the `eval` come from? – Benjamin W. Aug 13 '23 at 20:01
  • 2
    The `eval` is unnecessary, and potentially dangerous. The example works fine for me. I guess that you may have some unusual characters in your `temp.txt` file (e.g. something that looks like a `%`). Check the output of `cat -et temp.txt`. – pjh Aug 13 '23 at 20:06
  • 1
    what are you expecting as the output for `http%3A%2F%2F`? I get `http://` – markp-fuso Aug 13 '23 at 20:22
  • Whehn I run `urldecode http%3A%2F%2F`, I get on standard output `http://`. The function is fine (try it!), but I don't understand how you script is being used; and of course the `eval` silly. – user1934428 Aug 14 '23 at 05:48

0 Answers0