[Top][All Lists]

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

Re: address@hidden expansion includes 0x01 and 0x02

From: Dennis Williamson
Subject: Re: address@hidden expansion includes 0x01 and 0x02
Date: Thu, 5 Nov 2015 18:45:45 -0600

On Wed, Oct 28, 2015 at 8:55 AM, Chet Ramey <address@hidden> wrote:
On 10/27/15 5:02 PM, Greg Wooledge wrote:
> I decided to play around with the address@hidden expansion in 4.4-beta.
> imadev:~$ red=$(tput setaf 1) reset=$(tput sgr0) x='address@hidden:\w\$ '; printf %s "address@hidden" | od -t x1
> 0000000    1  1b  5b  33  31  6d   2  77  6f  6f  6c  65  64  67   1  1b
> 0000020   5b  6d   f   2  40  69  6d  61  64  65  76  3a  7e  24  20
> 0000037
> I don't think the "1" and "2" bytes should be printed.  They're for
> internal use only, even if they're usually invisible.

That's what the \[ and \] escape sequences expand to and use to
communicate information to readline about invisible characters in the
use the expansion of address@hidden as, for instance, the prompt passed to
readline when using `read -e -p prompt', those characters need to be there.

``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/

To follow on to what Greg said:

The only way I've found to output a string containing non-printing sequence delimiters using the @P transformation is to use read -e -p or to strip the \[ and \] first. All the other prompt escapes work in printf or echo -e when using @P.

To reproduce:

red=$(tput setaf 1)
none=$(tput sgr0)
printf '%s\n' "address@hidden"
echo -e "address@hidden"
read -e -p "address@hidden"

Naively stripping the delimiters in this case would leave $redHELLO$none where $redHello is unset or worse.

Granted it makes no sense to have non-printing sequences delimited when readline isn't involved, but it makes things simpler if you're dealing with a pre-existing string.

So if @P needs to output \001 and \002 then perhaps there needs to be an @p which doesn't (unless there's a way to determine whether readline is involved and only output the delimiters in that case).

Visit serverfault.com to get your system administration questions answered.

reply via email to

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