help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: string escaping in bash


From: Alex fxmbsw7 Ratchev
Subject: Re: string escaping in bash
Date: Fri, 12 Mar 2021 23:13:59 +0100

i think that also suffers the bugs i had, but not sure

On Fri, Mar 12, 2021 at 11:07 PM Pier Paolo Grassi <pierpaolog@gmail.com>
wrote:

> In zsh this could be solved like this:
>
> local -A conversions=(n $'\n' t $'\t' \\ \\)
> example='\a\n\c\\\t\e'
> echo -E - ${example//(#b)\\(?)/${conversions[$match[1]]:-\\$match[1]}}
>
> but I don't know if this can be expressed with bash syntax, maybe someone
> can help me translate it?
>
> Pier Paolo Grassi
>
>
> Il giorno ven 12 mar 2021 alle ore 22:48 Alex fxmbsw7 Ratchev <
> fxmbsw7@gmail.com> ha scritto:
>
>> i think i cannot succeed
>> the most was the v=nonexist// version
>>
>> thank you
>>
>> On Fri, Mar 12, 2021 at 10:41 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
>> wrote:
>>
>> > thank you
>> >
>> > i may post a new version soon whenever i succeed it, i just gotta think
>> > more about it
>> >
>> > thank you again
>> >
>> > On Fri, Mar 12, 2021 at 10:37 PM Lawrence Velázquez <vq@larryv.me>
>> wrote:
>> >
>> >> > On Mar 12, 2021, at 3:25 PM, Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com
>> >
>> >> wrote:
>> >> >
>> >> > this is without keep over and does the stupid non edge cases
>> >> > maybe you can give me better test cases ?
>> >> >
>> >> > i=-1 res=( ) list=( '\one' '\\Two' '\\\Three' '\\\\four' '\\\\\five'
>> )
>> >> > right=( '\one' '\Two' '\\Three' '\\four' '\\\five' ) ; for str in
>> >> > "${list[@]}" ; do str=${str//\\n/$'\n'} str=${str//\\t/$'\t'}
>> >> > res[++i]=${str//\\\\/\\} ; printf '%d %s %s\n' $i "${res[i]}"
>> >> "${right[i]}"
>> >> > ; done
>> >>
>> >>         bash-5.1$ str='\\n'
>> >>         bash-5.1$ printf '%s' "$str" | od -A n -t a -t x1
>> >>                    \   \   n
>> >>                    5c  5c  6e
>> >>
>> >> This should become '\n' (0x5c 0x6e).
>> >>
>> >>         bash-5.1$ str=${str//\\n/$'\n'}
>> >>         bash-5.1$ str=${str//\\t/$'\t'}
>> >>         bash-5.1$ str=${str//\\\\/\\}
>> >>         bash-5.1$ printf '%s' "$str" | od -A n -t a -t x1
>> >>                    \  nl
>> >>                    5c  0a
>> >>
>> >> --
>> >> vq
>> >>
>> >>
>>
>


reply via email to

[Prev in Thread] Current Thread [Next in Thread]