help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How not to include the trailing newline when <<< is used


From: Greg Wooledge
Subject: Re: [Help-bash] How not to include the trailing newline when <<< is used?
Date: Thu, 26 May 2016 08:17:45 -0400
User-agent: Mutt/1.4.2.3i

On Wed, May 25, 2016 at 04:41:34PM -0500, Dan Douglas wrote:
> Getting the string length in bytes while assigning so that `head -c`
> does the "right" thing - assuming you have `head -c` and it doesn't
> randomly disagree with `tail -c` on measuring bytes.

SYNOPSIS
     head [-c|-l] [-n count] [file ...]

There's a -c on this platform, but it doesn't take an argument.  You
have to specify -c -n count.  Also, head adds a newline anyway:

imadev:~$ head -c -n 4 <<< 'hell'; echo o
hell
o

This one works better, and is more portable:

imadev:~$ dd bs=4 count=1 2>/dev/null <<< 'hell'; echo o
hello

I still prefer "No".  It's just so much cleaner and easier to stop using
the syntax that adds a newline when you don't want to add a newline.
Use < <(printf...) instead.  It doesn't add a newline, so you don't need
hacks to remove the newline after the fact.

imadev:~$ cat < <(printf %s hell); echo o
hello

> So your $'\uHHHH' isn't working for some reason. Was bash configured
> with whatever it is that sets HANDLE_MULTIBYTE for the bit in
> strtrans.c that deals with \u? config.h says it's on by default for
> platforms that support it. I don't know.

In config-bot.h it gets turned on if a whole slew of other HAVE_*
symbols are defined, one of those being HAVE_MBSRTOWCS.  This symbol
is undefined on my platform.  Probably others too, but that's the first
one I found.  (And indeed, "No manual entry for mbsrtowcs.")



reply via email to

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