[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: string escaping in bash
From: |
Peng Yu |
Subject: |
Re: string escaping in bash |
Date: |
Sat, 13 Mar 2021 07:51:57 -0600 |
On Sat, Mar 13, 2021 at 6:18 AM Koichi Murase <myoga.murase@gmail.com>
wrote:
> 2021年3月12日(金) 23:06 Peng Yu <pengyu.ut@gmail.com>:
> > I wondering if there is a simple but robust way to implement string
> escaping.
> >
> > Specifically, the string "\n" (a slash and the letter "n") should be
> [...] All other
> > characters and their preceding slash (if there is) should remain as
> > is.
>
> I think this is `unescaping' rather than `escaping'.
You are right. It should be unescape. My function name reflects this. But
the original question was wrong in this aspect.
>
>
> > Does anybody have a robust way to implement this in bash?
>
> function unescape-helpbash202103-47 {
> local s=$1
> s=${s//z/z0}
This idea is great. It can be a general approach to solve the problem of
custom unescaping without the support of regex replacement.
>
> s=${s//'\\'/z1}
> s=${s//'\n'/$'\n'}
> s=${s//'\t'/$'\t'}
> s=${s//z1/'\'}
> s=${s//z0/z}
> result=$s
> }
> unescape-helpbash202103-47 '\\n'; x=$result
> declare -p x | cat -v
>
> Result:
>
> declare -- x="\\n"
>
> --
> Koichi
>
--
Regards,
Peng
- Re: string escaping in bash, (continued)
- Re: string escaping in bash, Lawrence Velázquez, 2021/03/12
- Re: string escaping in bash, Alex fxmbsw7 Ratchev, 2021/03/12
- Re: string escaping in bash, Alex fxmbsw7 Ratchev, 2021/03/12
- Re: string escaping in bash, Pier Paolo Grassi, 2021/03/12
- Re: string escaping in bash, Alex fxmbsw7 Ratchev, 2021/03/12
- Re: string escaping in bash, Pier Paolo Grassi, 2021/03/12
Re: string escaping in bash, Eli Schwartz, 2021/03/12
Re: string escaping in bash, Koichi Murase, 2021/03/13
- Re: string escaping in bash,
Peng Yu <=