[Top][All Lists]

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

\c-handling in $'-strings

From: Helmut Karlowski
Subject: \c-handling in $'-strings
Date: Sat, 29 Aug 2015 00:28:35 +0100
User-agent: Opera Mail/12.16 (Win32)


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

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).


reply via email to

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