Bash, not all strings in a text are url decoded

58 Views Asked by At

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.

0

There are 0 best solutions below