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

Re: [libvirt] [PATCH] [TCK] Convert scripts to also run with dash



On 11/15/2010 11:24 AM, Stefan Berger wrote:
> I tried this now and converted all \\ to \. I still get the same problem
> here with dash using 'read -r line' now. The same problem exists with
> 
> echo "\1"
> 
> or
> 
> echo '\1'

Ah - the plot thickens, and the light bulb goes on for me.  It's not
just a problem with read, but also with your use of 'echo' to try and
replay a just-read string.  'echo' and '\' don't mix.  You have to use
printf for any chance of portability.

printf %s\\n "\1"
printf %s\\n '\1'

> 
> run via bash or dash. Bash prints out '\1' and dash (0.5.6-2.fc14)
> prints char(1) in both cases.

Yes, because dash's echo is POSIX-compliant by default, and bash's is
(intentionally) not.  'shopt -s xpg_echo' in bash to get bash behaving
more like POSIX in automatically interpolating \, although you'll still
get a difference in whether \1 gets interpolated to char(1), since POSIX
only requires interpolation of \0nnn (dash's interpolation of \1 is an
extension):

$ dash -c "echo '"'\1'\' | od -tx1
0000000 01 0a
0000002
$ shopt -s xpg_echo
$ echo '\1'
\1
$ echo '\041'
!
$ shopt -u xpg_echo
$ echo '\041'
\041
ke office (0) ~/libvirt
$ dash -c "echo '"'\041'\'
!
$ dash -c 'printf %s\\n "\\041"'
\041

-- 
Eric Blake   eblake redhat com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature


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