Re: Using << and an output pipe together in shell (bash)

Liste des Groupes 
Sujet : Re: Using << and an output pipe together in shell (bash)
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.unix.shell
Date : 01. Nov 2024, 01:49:46
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vg18jc$2tv5s$1@dont-email.me>
References : 1 2 3
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 01.11.2024 00:05, Kenny McCormack wrote:
In article <87r07v99wd.fsf@bsb.me.uk>, Ben Bacarisse  <ben@bsb.me.uk> wrote:
...
I think you need "| \" at the end of this line.  At least that's what I
usually do and it seems to work.
 
It is not generally necessary to put a backslash at the end of a line that
ends with | (in shell script).
 
But it *is* necessary in this special case!

Unless you put the 'nl' at the "right place"; you can write your
example below as

$ nl << EOF |
test
this
EOF
nl

so the backslash is not "necessary". - As you say, the '|' needs no
[spurious] continuation escape character if you have it at the end
of a command. - After the lines that define the here-doc (for 'nl's
redirection) the pipe command gets continued on the subsequent line,
which is the line after the "EOF".

So, you get the prize.
Note that this solves it as far as getting bash to be happy with it is
concerned.  When I get a chance, I need to see about how VIM feels about it.
 
Here's test case:
 
 $ nl << EOF | nl
test
this
EOF
     1       1  test
     2       2  this
$ nl << EOF |
nl
test
this
EOF

Here, 'nl' is part of the here-doc data. so the pipe has no process
to feed its data in. You can see that if you add, say, another 'nl'
behind the "EOF" and you'll get
     1      1 nl
     2      2 test
     3      3 this

 
-bash5: syntax error: unexpected end of file
Status: 2
 $ nl << EOF | \
nl

(That's a spurious [unnecessary] escape I'd consider a hack. - But
okay, YMMV.)

Janis

test
this
EOF
     1       1  test
     2       2  this
 $
 


Date Sujet#  Auteur
31 Oct 24 * Using << and an output pipe together in shell (bash)10Kenny McCormack
31 Oct 24 +- Re: Using << and an output pipe together in shell (bash)1Janis Papanagnou
1 Nov 24 +* Re: Using << and an output pipe together in shell (bash)6Ben Bacarisse
1 Nov 24 i`* Re: Using << and an output pipe together in shell (bash)5Kenny McCormack
1 Nov 24 i +* Re: Using << and an output pipe together in shell (bash)3Janis Papanagnou
1 Nov 24 i i`* Re: Using << and an output pipe together in shell (bash)2Kenny McCormack
1 Nov 24 i i `- Re: Using << and an output pipe together in shell (bash)1Lem Novantotto
1 Nov 24 i `- Re: Using << and an output pipe together in shell (bash)1Kaz Kylheku
3 Nov 24 `* Re: Using << and an output pipe together in shell (bash)2Helmut Waitzmann
4 Nov 24  `- Re: Using << and an output pipe together in shell (bash)1Janis Papanagnou

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal