[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: string escaping in bash
From: |
Koichi Murase |
Subject: |
Re: string escaping in bash |
Date: |
Sat, 13 Mar 2021 20:18:18 +0800 |
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'.
> Does anybody have a robust way to implement this in bash?
function unescape-helpbash202103-47 {
local s=$1
s=${s//z/z0}
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
- Re: string escaping in bash, (continued)
- Re: string escaping in bash, Alex fxmbsw7 Ratchev, 2021/03/12
- 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 <=