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 21:25:34 +0100

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
0 \one \one
1 \Two \Two
2 \\Three \\Three
3 \\four \\four
4 \\\five \\\five

On Fri, Mar 12, 2021 at 9:20 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
wrote:

> so i failed the backslash only method
> there may be a method if it doesnt bug the same to replace first the
> replacement of \\ then later back
>
> till then only a nonexist string is there as place holder
> ill test if i even need a place holder, hm ?
>
> v=nonexist// i=-1 res=( ) list=( '\one' '\\Two' '\\\Three' '\\\\four'
> '\\\\\five' ) right=( '\one' '\Two' '\\Three' '\\four' '\\\five' ) ; for
> str in "${list[@]}" ; do str=${str//\\\\/$v} str=${str//\\n/$'\n'}
> str=${str//\\t/$'\t'} res[++i]=${str//$v/\\} ; printf '%d %s %s\n' $i
> "${res[i]}" "${right[i]}" ; done
> 0 \one \one
> 1 \Two \Two
> 2 \\Three \\Three
> 3 \\four \\four
> 4 \\\five \\\five
>
> On Fri, Mar 12, 2021 at 9:09 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
> wrote:
>
>> thers just the question of \o or \bla should return in \o or o or what
>>
>> On Fri, Mar 12, 2021 at 9:02 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
>> wrote:
>>
>>> i need some details of peng
>>> i wanted to make test cases for the backslashes
>>>
>>> list=( '\one' '\\Two' '\\\Three' '\\\\four' '\\\\\five' )
>>>
>>> which should result in output of
>>>
>>> right=( '\one' '\Two' '\\Three' '\\four' '\\\five' )
>>>
>>> there is collision
>>>
>>> please review and write
>>> especially if 'right' looks right
>>>
>>> On Fri, Mar 12, 2021 at 8:46 PM Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
>>> wrote:
>>>
>>>> thank you, fixing it.. trying some backslash only method now [or wish..]
>>>>
>>>> thank you tho !
>>>>
>>>> On Fri, Mar 12, 2021 at 8:45 PM Lawrence Velázquez <vq@larryv.me>
>>>> wrote:
>>>>
>>>>> > On Mar 12, 2021, at 2:28 PM, Alex fxmbsw7 Ratchev <fxmbsw7@gmail.com>
>>>>> wrote:
>>>>> >
>>>>> > i dunno ..thats what its supposed to give, \\ give a \
>>>>> > so the dude wanted in his initial mail[s]
>>>>>
>>>>> My fault, this is what I meant to send:
>>>>>
>>>>> bash-5.1$ str=$'contains ^A: \1'
>>>>> bash-5.1$ printf '%s' "$str" | od -ta -tx1
>>>>> 0000000    c   o   n   t   a   i   n   s  sp   ^   A   :  sp soh
>>>>>
>>>>>            63  6f  6e  74  61  69  6e  73  20  5e  41  3a  20  01
>>>>>
>>>>> 0000016
>>>>> bash-5.1$ str=${str//\\\\/$'\1'} str=${str//\\n/$'\n'}
>>>>> str=${str//\\t/$'\t'}
>>>>> bash-5.1$ str=${str//$'\1'/\\}
>>>>> bash-5.1$ printf '%s' "$str" | od -ta -tx1
>>>>> 0000000    c   o   n   t   a   i   n   s  sp   ^   A   :  sp   \
>>>>>
>>>>>            63  6f  6e  74  61  69  6e  73  20  5e  41  3a  20  5c
>>>>>
>>>>> 0000016
>>>>>
>>>>> As you can see, the SOH character (^A, \001, etc.) in the original
>>>>> string has been mangled.
>>>>>
>>>>> --
>>>>> vq
>>>>
>>>>


reply via email to

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