Replace percent-escaped characters in string ( , [, …) with bash

前端 未结 2 1083
无人及你
无人及你 2021-02-09 14:11

I have strings containing percent-escaped characters like %20 and %5B, and I would like to transform it to \"normal\" characters like \\ f

2条回答
  •  情书的邮戳
    2021-02-09 14:49

    The builtin printf in bash has a special format specifier (i.e. %b) which converts \x** to the corresponding value:

    $ str='foo%20%5B12%5D'
    $ printf "%b\n" "${str//%/\\x}"
    foo [12]
    

提交回复
热议问题