$"\t': Bash bug or not?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

$"\t': Bash bug or not?

Rick Richardson
$ echo "$LOGNAME " | xod

Dump: standard input

Offset:    0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f   0123456789abcdef

00000000: 72 69 63 6b 20 0a                                | rick .           |

OK!

$ echo "$'\t' " | xod

Dump: standard input

Offset:    0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f   0123456789abcdef

00000000: 24 27 5c 74 27 20 0a                             | $'\t' .          |

A Bash bug???

$ echo $'\t'' ' | xod

Dump: standard input

Offset:    0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f   0123456789abcdef

00000000: 09 20 0a                                         | . .              |

OK if you *don't quote it*.



--
Rick Richardson [hidden email] http://rickrich1.home.comcast.net/
Linux printer drivers for JBIG (GDI printers): Konica Minolta magicolor,
                          HP LaserJet, Samsung, Xerox, Lexmark, and Oki.
                                             http://foo2zjs.rkkda.com/
Linux tools for geocaching   http://geo.rkkda.com/
Gnome Manual Duplex         http://sourceforge.net/projects/g-manual-duplex/

Reply | Threaded
Open this post in threaded view
|

Re: $"\t': Bash bug or not?

Greg Wooledge
On Wed, Nov 15, 2017 at 09:01:52AM -0600, Rick Richardson wrote:
> $ echo "$'\t' " | xod
>
> Dump: standard input
>
> Offset:    0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f   0123456789abcdef
>
> 00000000: 24 27 5c 74 27 20 0a                             | $'\t' .          |
>
> A Bash bug???

No.  You're inside double quotes, so you parse the content accordingly.
Inside double quotes, $ may begin a parameter expansion, or an
arithmetic expansion, and so on.  But in this case, it does not.
So the $ is just taken literally.

If you want to use something that expands to a tab inside double quotes,
try this:

tab=$'\t'
echo "$tab " | xod
echo "${tab}indented" | xod

Reply | Threaded
Open this post in threaded view
|

Re: $"\t': Bash bug or not?

Chet Ramey
In reply to this post by Rick Richardson
On 11/15/17 10:01 AM, Rick Richardson wrote:

> $ echo "$'\t' " | xod
>
> Dump: standard input
>
> Offset:    0  1  2  3  4  5  6  7   8  9  a  b  c  d  e  f   0123456789abcdef
>
> 00000000: 24 27 5c 74 27 20 0a                             | $'\t' .          |
>
> A Bash bug???

Where's the bug? Since single quotes aren't special within double quotes,
what behavior do you expect?


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

Reply | Threaded
Open this post in threaded view
|

Re: $"\t': Bash bug or not?

Robert Elz
In reply to this post by Rick Richardson
To put Chet's reply a different way, don't think of $'...' as a dollar
expansion ( like ${} $() or $(()) ) it isn't, it is just another form of
quoting (very similar to '' quoting) and is processed in the same way,
at the same places, as '' quoting would be.

In "'xxx'" the single quotes are just characters.   So in "$'...'" the $' are
just characters (though probably strictly undefined behaviour, as $ followed
by something that is not a var name (or positional or special param name)
and is not { or ( is undefined, and $ inside " is supposed to be expanded,
but cannot be here.

kre


Reply | Threaded
Open this post in threaded view
|

Re: $"\t': Bash bug or not?

Peter & Kelly Passchier
In reply to this post by Greg Wooledge
On 11/15/2017 11:06 PM, Greg Wooledge wrote:
> On Wed, Nov 15, 2017 at 09:01:52AM -0600, Rick Richardson wrote:
> tab=$'\t'
> echo "$tab " | xod

Where can I get xod? I tried looking here https://github.com/xodio/xod 
and I found a perl script that couldn't be piped into.

Peter


Reply | Threaded
Open this post in threaded view
|

Re: $"\t': Bash bug or not?

Chris F.A. Johnson-6
On Sat, 18 Nov 2017, PePa wrote:

> On 11/15/2017 11:06 PM, Greg Wooledge wrote:
>> On Wed, Nov 15, 2017 at 09:01:52AM -0600, Rick Richardson wrote:
>> tab=$'\t'
>> echo "$tab " | xod
>
> Where can I get xod?

I don't know about xod, but od is a standard utility, and hd is also
commonly installed.

--
Chris F.A. Johnson, <http://cfajohnson.com>