bug-bash
[Top][All Lists]
Advanced

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

Re: echo $'\0' >a does not write the nul byte


From: Léa Gris
Subject: Re: echo $'\0' >a does not write the nul byte
Date: Mon, 18 Jan 2021 01:18:09 +0100
User-agent: Telnet/1.0 [tlh] (PDP11/DEC)

Le 17/01/2021 à 22:02, Chet Ramey écrivait :
On 1/17/21 3:05 PM, hans@artax.karlin.mff.cuni.cz wrote:

Description:
    Command
        echo $'\0' |od -c
    writes
        0000000  \n
        0000001
    in contrast to
        echo $'\1' |od -c
        0000000 001  \n
        0000002
    The nul byte is not echoed by $'\0'.

Repeat-By:
    echo $'\0' |od -c
    echo $'\1' |od -c

Shell builtin commands obey the same argv conventions as any other Unix
program: arguments are null-terminated strings. That means that

echo $'\0'
echo ''
echo ""

are all equivalent, and none of them will output a null byte.


The only way to output a null byte with shell built-in is:

printf '\0'
or non portable: echo -ne '\0'

This is because `\0' is not a null byte or a nulll string but interpreted internally to the command to print a null byte.

--
Léa Gris




reply via email to

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