PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Where does the trailing '\n' come from?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Where does the trailing '\n' come from?

Réponse
 
LinkBack Outils de la discussion
Vieux 21/04/2008, 05h50   #1
PRC
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Where does the trailing '\n' come from?

---------------------------------------------------------------------------
$cat <<<'Mary has a little lamb!'
Mary has a little lamb!

---------------------------------------------------------------------------
There is an unexpected '\n' in the end. Unlike echo, cat won't output
a <newline>
after the string. So where does the trailing '\n' come from? Maybe it
is related
to the Here String. But it is not mentioned in the bash manual.

Best Regards,
PRC
Apr 21, 2008
  Réponse avec citation
Vieux 21/04/2008, 08h54   #2
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Where does the trailing '\n' come from?

On Monday 21 April 2008 06:50, PRC wrote:

> ---------------------------------------------------------------------------
> $cat <<<'Mary has a little lamb!'
> Mary has a little lamb!
>
> ---------------------------------------------------------------------------
> There is an unexpected '\n' in the end. Unlike echo, cat won't output
> a <newline> after the string. So where does the trailing '\n' come from?
> Maybe it is related to the Here String. But it is not mentioned in the
> bash manual.


Well, since the <<< construct accepts strings *only on the same line*, I
think the \n is implied, since it would be difficult to differentiate the
case where it's wanted and where it's not.
However, it seems you are using bash, so I think you can use something like

cat <(printf "%s" "Mary had a little lamb")

to achieve the same result. Or, of course, just

printf "%s" "Mary had a little lamb"

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 21/04/2008, 11h54   #3
Florian Kaufmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Where does the trailing '\n' come from?

> Well, since the <<< construct accepts strings *only on the same line*, I

Why you think is that so?

$ cat <<< 'hello
> test'

hello
test
$ $0 --version
GNU bash, version 3.2.33(18)-release (i686-pc-cygwin)
Copyright (C) 2007 Free Software Foundation, Inc.
  Réponse avec citation
Vieux 21/04/2008, 11h56   #4
Florian Kaufmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Where does the trailing '\n' come from?


The previous post was mysteriously ill formated.

$ cat <<< 'hello
> test'

hello
test

  Réponse avec citation
Vieux 21/04/2008, 11h58   #5
Florian Kaufmann
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Where does the trailing '\n' come from?

Sorry - I don't get it to work. There shouldn't be any empty lines
anywhere.
  Réponse avec citation
Vieux 21/04/2008, 12h03   #6
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Where does the trailing '\n' come from?

On Monday 21 April 2008 12:54, Florian Kaufmann wrote:

>> Well, since the <<< construct accepts strings *only on the same line*, I

>
> Why you think is that so?
>
> $ cat <<< 'hello
>> test'

> hello
> test


Ok, sorry, bad wording. I meant the construct accepts only a single string,
which may contain newlines of course. Still, since there is no explicit
ending delimiter (unlike in <<), I think it would be difficult, with the
current syntax, for the shell to understand whether the user wants the
trailing \n or not.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Vieux 21/04/2008, 12h11   #7
pk
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Where does the trailing '\n' come from?

On Monday 21 April 2008 13:03, pk wrote:

> Ok, sorry, bad wording. I meant the construct accepts only a single
> string, which may contain newlines of course. Still, since there is no
> explicit ending delimiter (unlike in <<), I think it would be difficult,
> with the current syntax, for the shell to understand whether the user
> wants the trailing \n or not.


And, what the OP wants is not possible with the traditional here-document
(<<) either, despite the explicit terminator, since it must be on a single
line by itself, and thus the previous line must end with a \n.

--
All the commands are tested with bash and GNU tools, so they may use
nonstandard features. I try to mention when something is nonstandard (if
I'm aware of that), but I may miss something. Corrections are welcome.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11121 seconds with 15 queries