help-bash
[Top][All Lists]
Advanced

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

Re: Format of here-documents


From: Andreas Kusalananda Kähäri
Subject: Re: Format of here-documents
Date: Tue, 14 Mar 2023 20:38:39 +0100

On Tue, Mar 14, 2023 at 03:09:06PM +0000, goncholden wrote:
> 
> 
> 
> 
> 
> Sent with Proton Mail secure email.
> 
> ------- Original Message -------
> On Wednesday, March 15th, 2023 at 3:01 AM, goncholden 
> <goncholden@protonmail.com> wrote:
> 
> 
> > 
> > 
> > 
> > 
> > 
> > Sent with Proton Mail secure email.
> > 
> > 
> > ------- Original Message -------
> > On Wednesday, March 15th, 2023 at 2:28 AM, Andreas Kusalananda Kähäri 
> > andreas.kahari@abc.se wrote:
> > 
> > 
> > 
> > > On Tue, Mar 14, 2023 at 11:58:16AM +0000, goncholden via wrote:
> > > 
> > > > Have been reading the manual about Here-Documents.
> > > > 
> > > > The format of here-documents is:
> > > > 
> > > > [
> > > > 
> > > > n
> > > > 
> > > > ]<<[-]
> > > > 
> > > > word
> > > > 
> > > > here-document
> > > > 
> > > > delimiter
> > > > 
> > > > But in practice I have seen the following
> > > > 
> > > > cat << _end_of_text
> > > > First Line
> > > > Second Line
> > > > Third Line
> > > > _end_of_text
> > > > 
> > > > Meaning that 'delimiter' is actually '
> > > > 
> > > > word'. Is this correct ?
> > > 
> > > From the bash manual:
> > > 
> > > If any part of word is quoted, the delimiter is the result of
> > > quote removal on word, and the lines in the here-document are
> > > not expanded.
> > > 
> > > Assumign that your issue with the manual is that the displayed syntax
> > > for here-documents does not say
> > > 
> > > [n]<<[-]word
> > > here-document
> > > word
> > > 
> > > ... the quoted sentence above should explain why the "word" and
> > > "delimiter" may be different (they would be if "word" is quoted in any
> > > way).
> 
> The start sentence is incorrect because the ending line must be DELIMITER, 
> not WORD.

Note that what I wrote before the incorrect example: "the displayed
syntax for here-documents does not say" (note the "not").

> 
> This type of redirection instructs the shell to read input from the current 
> source until a line containing only word (with no trailing blanks) is seen. 

Until the delimiter is seen, which is the same as the word if the word
is unquoted.  The delimiter most be flush right with no preceding
whitespace, unless the optional - is used before the word, in which case
tab characters are stripped from the start of the line.


-- 
Andreas (Kusalananda) Kähäri
SciLifeLab, NBIS, ICM
Uppsala University, Sweden

.



reply via email to

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