help-bash
[Top][All Lists]
Advanced

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

Re: string escaping in bash


From: Lawrence Velázquez
Subject: Re: string escaping in bash
Date: Fri, 12 Mar 2021 16:37:34 -0500

> 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]