Home » Questions » Computers [ Ask a new question ]

Linux urldecode filename

Linux urldecode filename

Is there any tool to urldecode a file's name and replace it?

Asked by: Guest | Views: 29
Total answers/comments: 2
Guest [Entry]

"A new blog post covers this with echo(1) and printf(1).

urldecode() {
arg=""$1""
i=""0""
while [ ""$i"" -lt ${#arg} ]; do
c0=${arg:$i:1}
if [ ""x$c0"" = ""x%"" ]; then
c1=${arg:$((i+1)):1}
c2=${arg:$((i+2)):1}
printf ""\x$c1$c2""
i=$((i+3))
else
echo -n ""$c0""
i=$((i+1))
fi
done
}"
Guest [Entry]

I think this Perl snippet can be used as a base for what you are looking for.