Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > gnu.bash.bug > #11443

\c-handling in $'-strings

From "Helmut Karlowski" <helmut.karlowski@ish.de>
Newsgroups gnu.bash.bug
Subject \c-handling in $'-strings
Date 2015-08-29 00:28 +0100
Organization Aioe.org NNTP Server
Message-ID <op.x33p5xjhofd6j1@nebbiolo.upc.de> (permalink)

Show all headers | View raw


Hello

The bash-manual says:

Words of the form $'string' are treated specially.  The word expands to  
string, with backslash-escaped  characters replaced as specified by the  
ANSI C standard.  Backslash escape sequences, if present, are decoded as  
follows:

...

  \cx    a control-x character

Now when I run this:

{
   echo $LINENO $'\h\ca\ek'
   echo $LINENO $'\h\cA\ek'
   echo $LINENO $'\h\cd\ek'
   echo $LINENO $'\h\c\d\ek'
   echo $LINENO $'\h\c|d\ek'
   echo $LINENO $'\h\c<d\ek'
   echo $LINENO $'\h\c d\ek'
   echo $LINENO $'\h\\c d\ek'
} | tee /dev/stderr | od -ax

I get (output pasted from my editor):

2 \h^A^[k
3 \h^A^[k
4 \h^D^[k
5 \h^\d^[k
6 \h^\d^[k
7 \h^\d^[k
8 \h
9 \h\c d^[k
0000000   2  sp   \   h soh esc   k  nl   3  sp   \   h soh esc   k  nl
            2032    685c    1b01    0a6b    2033    685c    1b01    0a6b
0000020   4  sp   \   h eot esc   k  nl   5  sp   \   h  fs   d esc   k
            2034    685c    1b04    0a6b    2035    685c    641c    6b1b
0000040  nl   6  sp   \   h  fs   d esc   k  nl   7  sp   \   h  fs   d
            360a    5c20    1c68    1b64    0a6b    2037    685c    641c
0000060 esc   k  nl   8  sp   \   h  nl   9  sp   \   h   \   c  sp   d
            6b1b    380a    5c20    0a68    2039    685c    635c    6420
0000100 esc   k  nl
            6b1b    000a
0000103

I wonder about the lines 6, 7, 8: 6,7: all non-alnum-characters (here |  
and <) are printed as 0x1c?
And line 8: Why is the output truncated after '\c '?

What I'd expect is:

6 \h<d^[k
7 \h|d^[k
8 \h`d^[k

that is an ^ 0x40-operation on the character following the \c. Is there an  
intention for bash's behaviour?

Version is: GNU bash, version 4.3.39(2)-release (i686-pc-cygwin).

-Helmut

Back to gnu.bash.bug | Previous | NextNext in thread | Find similar


Thread

\c-handling in $'-strings "Helmut Karlowski" <helmut.karlowski@ish.de> - 2015-08-29 00:28 +0100
  Re: \c-handling in $'-strings Chet Ramey <chet.ramey@case.edu> - 2015-08-31 10:17 -0400
    Re: \c-handling in $'-strings "Helmut Karlowski" <helmut.karlowski@ish.de> - 2015-09-01 23:46 +0100
      Re: \c-handling in $'-strings Chet Ramey <chet.ramey@case.edu> - 2015-09-02 09:19 -0400
        Re: \c-handling in $'-strings "Helmut Karlowski" <helmut.karlowski@ish.de> - 2015-09-02 22:10 +0100
          Re: \c-handling in $'-strings Eric Blake <eblake@redhat.com> - 2015-09-02 15:44 -0600
          Re: \c-handling in $'-strings Chet Ramey <chet.ramey@case.edu> - 2015-09-03 09:58 -0400

csiph-web