Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

BOFH excuse #430: Mouse has out-of-cheese-error


comp / comp.unix.shell / Re: Using << and an output pipe together in shell (bash)

SubjectAuthor
* Using << and an output pipe together in shell (bash)Kenny McCormack
+- Re: Using << and an output pipe together in shell (bash)Janis Papanagnou
+* Re: Using << and an output pipe together in shell (bash)Ben Bacarisse
|`* Re: Using << and an output pipe together in shell (bash)Kenny McCormack
| +* Re: Using << and an output pipe together in shell (bash)Janis Papanagnou
| |`* Re: Using << and an output pipe together in shell (bash)Kenny McCormack
| | `- Re: Using << and an output pipe together in shell (bash)Lem Novantotto
| `- Re: Using << and an output pipe together in shell (bash)Kaz Kylheku
`* Re: Using << and an output pipe together in shell (bash)Helmut Waitzmann
 `- Re: Using << and an output pipe together in shell (bash)Janis Papanagnou

1
Subject: Using << and an output pipe together in shell (bash)
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Thu, 31 Oct 2024 20:44 UTC
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Using << and an output pipe together in shell (bash)
Date: Thu, 31 Oct 2024 20:44:29 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vg0q7d$3tlel$2@news.xmission.com>
Injection-Date: Thu, 31 Oct 2024 20:44:29 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="4117973"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

Consider this code in a bash script:

(Note: No actual indentation is intended - only shown like this for posting)

someCommand ... << EOF | someOtherCommand
some data
for someCommand
EOF

This should work, right?

In simple cases, it does (seem to) work OK.

However, in the actual real world case, it is more like:

someCommand -x -y "sjdfhk" and more options \
-g and still more options -Q "another option" << EOF |
/usr/lib/ANotherCommand -x "with option" and "more options"
some data
for someCommand
EOF

This time, two things happen:

When edited with GVIM, everything after the line that ends with | is
highlighted as if it was an unterminated string (that is, in a purple/pink
color) and when the above file is dotted, bash complains about "Syntax
error: Unexpected end of file" - as if it never seems the EOF tag.

In the end, I ended up replacing the " << EOF | ANotherCommand ..." construct with:

> >(ANotherCommand ...) << EOF

and all is well. But why? Should this be necessary?
Yes, I know it is hard to debug this w/o specifics, but I really don't
think the specifics matter; they would be hard to reproduce here.

I just want to know if the basic syntax is valid and/or if there is a
better workaround (better than switching to: > >(...))

--
Many North Koreans believe Kim-il-Sung is an "almighty god" who "created
the world" in seven days as a divine spirit millions of years ago, and
came to Earth as a human in 1912 as a messianic figure.

Subject: Re: Using << and an output pipe together in shell (bash)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Thu, 31 Oct 2024 20:57 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Using << and an output pipe together in shell (bash)
Date: Thu, 31 Oct 2024 21:57:43 +0100
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <vg0r09$2ro7o$1@dont-email.me>
References: <vg0q7d$3tlel$2@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 31 Oct 2024 21:57:45 +0100 (CET)
Injection-Info: dont-email.me; posting-host="0b42ec05b39173c9a9635a2046be83b4";
logging-data="3006712"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX183PiWAq4q6w6nW+rvQtMXD"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:jyIhOgltnfY3rDC0yfJnB5/8cnE=
In-Reply-To: <vg0q7d$3tlel$2@news.xmission.com>
View all headers

On 31.10.2024 21:44, Kenny McCormack wrote:
> Consider this code in a bash script:
>
> (Note: No actual indentation is intended - only shown like this for posting)
>
> someCommand ... << EOF | someOtherCommand
> some data
> for someCommand
> EOF
>
> This should work, right?
>
> In simple cases, it does (seem to) work OK.
>
> However, in the actual real world case, it is more like:
>
> someCommand -x -y "sjdfhk" and more options \
> -g and still more options -Q "another option" << EOF |
> /usr/lib/ANotherCommand -x "with option" and "more options"
> some data
> for someCommand
> EOF

This complexity is not helping much to see what issue you have also
when mentioning syntax highlighting problems.

All I can say at the moment - and you decide whether that's relevant
for your case - is that, say, instead of syntax

cat \
-n << EOF |
wc -l
some data
for someCommand
EOF

you might rather want

cat \
-n << EOF |
some data
for someCommand
EOF
wc -l

HTH.

Janis

>
> This time, two things happen:
>
> When edited with GVIM, everything after the line that ends with | is
> highlighted as if it was an unterminated string (that is, in a purple/pink
> color) and when the above file is dotted, bash complains about "Syntax
> error: Unexpected end of file" - as if it never seems the EOF tag.
>
> In the end, I ended up replacing the " << EOF | ANotherCommand ..." construct with:
>
> > >(ANotherCommand ...) << EOF
>
> and all is well. But why? Should this be necessary?
> Yes, I know it is hard to debug this w/o specifics, but I really don't
> think the specifics matter; they would be hard to reproduce here.
>
> I just want to know if the basic syntax is valid and/or if there is a
> better workaround (better than switching to: > >(...))
>

Subject: Re: Using << and an output pipe together in shell (bash)
From: Ben Bacarisse
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Thu, 31 Oct 2024 22:37 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ben@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.shell
Subject: Re: Using << and an output pipe together in shell (bash)
Date: Thu, 31 Oct 2024 22:37:22 +0000
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <87r07v99wd.fsf@bsb.me.uk>
References: <vg0q7d$3tlel$2@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Date: Thu, 31 Oct 2024 23:37:30 +0100 (CET)
Injection-Info: dont-email.me; posting-host="7eabcca1e5b2acef4fd1f9002cd3898a";
logging-data="3032598"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IWXJQtekRFA5/ENZQcqiCUaYRfxx5LAg="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:DNTeKP1Xz04rrVBijT4DZHS+j1Q=
sha1:1mUhzxEoS5NYgOyR78OkTpxzgMk=
X-BSB-Auth: 1.e2eefceef1af6e4625f7.20241031223722GMT.87r07v99wd.fsf@bsb.me.uk
View all headers

gazelle@shell.xmission.com (Kenny McCormack) writes:

> Consider this code in a bash script:
>
> (Note: No actual indentation is intended - only shown like this for posting)
>
> someCommand ... << EOF | someOtherCommand
> some data
> for someCommand
> EOF
>
> This should work, right?
>
> In simple cases, it does (seem to) work OK.
>
> However, in the actual real world case, it is more like:
>
> someCommand -x -y "sjdfhk" and more options \
> -g and still more options -Q "another option" << EOF |

I think you need "| \" at the end of this line. At least that's what I
usually do and it seems to work.

> /usr/lib/ANotherCommand -x "with option" and "more options"
> some data
> for someCommand
> EOF

--
Ben.

Subject: Re: Using << and an output pipe together in shell (bash)
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Thu, 31 Oct 2024 23:05 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Using << and an output pipe together in shell (bash)
Date: Thu, 31 Oct 2024 23:05:20 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vg12fg$3tq77$1@news.xmission.com>
References: <vg0q7d$3tlel$2@news.xmission.com> <87r07v99wd.fsf@bsb.me.uk>
Injection-Date: Thu, 31 Oct 2024 23:05:20 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="4122855"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

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! 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

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

--
It's possible that leasing office space to a Starbucks is a greater liability
in today's GOP than is hitting your mother on the head with a hammer.

Subject: Re: Using << and an output pipe together in shell (bash)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Fri, 1 Nov 2024 00:49 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Using << and an output pipe together in shell (bash)
Date: Fri, 1 Nov 2024 01:49:46 +0100
Organization: A noiseless patient Spider
Lines: 70
Message-ID: <vg18jc$2tv5s$1@dont-email.me>
References: <vg0q7d$3tlel$2@news.xmission.com> <87r07v99wd.fsf@bsb.me.uk>
<vg12fg$3tq77$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 01 Nov 2024 01:49:48 +0100 (CET)
Injection-Info: dont-email.me; posting-host="b6d3c62206b25276986a6f20f582af8e";
logging-data="3079356"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19az8cQpVV5oIIp6QuxPQUe"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:h2NmUa6UW9u6kXfVh1gHSaMl4IM=
In-Reply-To: <vg12fg$3tq77$1@news.xmission.com>
X-Enigmail-Draft-Status: N1110
View all headers

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
> $
>

Subject: Re: Using << and an output pipe together in shell (bash)
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Fri, 1 Nov 2024 09:01 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder2.eternal-september.org!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.unix.shell
Subject: Re: Using << and an output pipe together in shell (bash)
Date: Fri, 1 Nov 2024 09:01:15 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vg25cr$3uc49$1@news.xmission.com>
References: <vg0q7d$3tlel$2@news.xmission.com> <87r07v99wd.fsf@bsb.me.uk> <vg12fg$3tq77$1@news.xmission.com> <vg18jc$2tv5s$1@dont-email.me>
Injection-Date: Fri, 1 Nov 2024 09:01:15 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="4141193"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
View all headers

In article <vg18jc$2tv5s$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
....
>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".

Yes, that works, too. Thanks.

Somewhat surprisingly (to me, anyway), I think I actually prefer to stick
with; > >(cmd ...)

That has a certain beauty to it.

--
Reading any post by Fred Hodgin, you're always faced with the choice of:
lunatic, moron, or troll.

I always try to be generous and give benefit of the doubt, by assuming troll.

Subject: Re: Using << and an output pipe together in shell (bash)
From: Kaz Kylheku
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Fri, 1 Nov 2024 15:19 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 643-408-1753@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.shell
Subject: Re: Using << and an output pipe together in shell (bash)
Date: Fri, 1 Nov 2024 15:19:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <20241101081200.462@kylheku.com>
References: <vg0q7d$3tlel$2@news.xmission.com> <87r07v99wd.fsf@bsb.me.uk>
<vg12fg$3tq77$1@news.xmission.com>
Injection-Date: Fri, 01 Nov 2024 16:19:48 +0100 (CET)
Injection-Info: dont-email.me; posting-host="7b1bf8980c4617c84d772d79224bae35";
logging-data="3465361"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+tk/KS0CDA5s19XEu90GMkq/pV4pfbNgI="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:NL/IfaGRn4CT7eBdLFguZ2sbnSk=
View all headers

On 2024-10-31, Kenny McCormack <gazelle@shell.xmission.com> 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).

The << feature works outside of the ordinary shell grammar, fetching
data in a line-oriented way until the delimiter.

If you have multiple occurrences, both their data parts go after
the command:

cmd1 << EOF | cmd2 << EOF | cmd3 << EOF
data1
EOF
data2
EOF
data3
EOF

Actual run with && rather than |:

$ cat << EOF && cat << EOF && cat << EOF
> foo
> EOF
> bar
> EOF
> xyzzy
> EOF
foo
bar
xyzzy

It looks like the implementation of << pulls logical lines (after
backslash folding) during parsing.

If this entire command pipe were parsed first:

cmd1 << EOF | cmd2 << EOF | cmd3 << EOF

and then a second pass took place to fetch the EOF-delimited pieces of
syntax that it requires, then it could contain artbitrary backslahes.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Subject: Re: Using << and an output pipe together in shell (bash)
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Fri, 1 Nov 2024 15:39 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Using << and an output pipe together in shell (bash)
Date: Fri, 1 Nov 2024 15:39:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <vg2snp$36bh5$1@dont-email.me>
References: <vg0q7d$3tlel$2@news.xmission.com> <87r07v99wd.fsf@bsb.me.uk>
<vg12fg$3tq77$1@news.xmission.com> <vg18jc$2tv5s$1@dont-email.me>
<vg25cr$3uc49$1@news.xmission.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 01 Nov 2024 16:39:37 +0100 (CET)
Injection-Info: dont-email.me; posting-host="a88e548459fc226e0e66a7d936d8e0ba";
logging-data="3354149"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+almLQZN/RYerXMEzmtWTggh/m2RtoWa0="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:OfwXxdHY+FJZWaQjNR/qacJDG1k=
View all headers

Il Fri, 1 Nov 2024 09:01:15 -0000 (UTC), Kenny McCormack ha scritto:

> I think I actually prefer to stick with; > >(cmd ...)

Note that

cat << EOF | grep . ; echo end

and also

(cat | grep .) << EOF ; echo end

produce the same output:
---------------------------------------------------------
lem@biggy:~$ cat << EOF | grep . ; echo end
start
EOF
start
end
lem@biggy:~$
---------------------------------------------------------
lem@biggy:~$ (cat | grep .) << EOF ; echo end
> start
> EOF
start
end
lem@biggy:~$
---------------------------------------------------------

Instead with "cat << EOF > >(grep .) ; echo end" the output is
unpredictable. You can very well get, as usual:
---------------------------------------------------------
lem@biggy:~$ cat << EOF > >(grep .) ; echo end
start
EOF
start
end
lem@biggy:~$
---------------------------------------------------------
OR maybe:
---------------------------------------------------------
lem@biggy:~$ cat << EOF > >(grep .) ; echo end
start
EOF
end
start
lem@biggy:~$
---------------------------------------------------------
OR even, most of the time:
---------------------------------------------------------
lem@biggy:~$ cat << EOF > >(grep .) ; echo end
start
EOF
end
lem@biggy:~$ start [you press ENTER here and get back an empty prompt]

lem@biggy:~$
---------------------------------------------------------

So sometimes it's better to be careful. :)
--
Bye, Lem

Subject: Re: Using << and an output pipe together in shell (bash)
From: Helmut Waitzmann
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 3 Nov 2024 20:37 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: nn.throttle@xoxy.net (Helmut Waitzmann)
Newsgroups: comp.unix.shell
Subject: Re: Using << and an output pipe together in shell (bash)
Date: Sun, 03 Nov 2024 21:37:07 +0100
Organization: A noiseless patient Spider
Lines: 83
Sender: Helmut Waitzmann <12f7e638@mail.de>
Message-ID: <83ikt4vyto.fsf@helmutwaitzmann.news.arcor.de>
References: <vg0q7d$3tlel$2@news.xmission.com>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: quoted-printable
Injection-Date: Sun, 03 Nov 2024 22:03:01 +0100 (CET)
Injection-Info: dont-email.me; posting-host="45f5efc88b2aa6b3f382e9c5aaaa9fbd";
logging-data="578364"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qurnpxpcSBOS19pwNY69m3xchbBLgH98="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:A8UWYzXJoJygCLSsVLMMfB3vDLU=
sha1:t7t2DZ3pj4c7gL3bBDefX9KRJnY=
Mail-Copies-To: nobody
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
View all headers

gazelle@shell.xmission.com (Kenny McCormack):
> Consider this code in a bash script:
>
>
> (Note: No actual indentation is intended - only shown like this
> for posting)
>
>
> someCommand ... << EOF | someOtherCommand
> some data
> for someCommand
> EOF
>
> This should work, right?
>
>
> In simple cases, it does (seem to) work OK.
>
>
> However, in the actual real world case, it is more like:
>
>
> someCommand -x -y "sjdfhk" and more options \
> -g and still more options -Q "another option" << EOF |
> /usr/lib/ANotherCommand -x "with option" and "more options"
> some data
> for someCommand
> EOF
>
> This time, two things happen:
>
>
> When edited with GVIM, everything after the line that ends with
> | is highlighted as if it was an unterminated string (that is,
> in a purple/pink color) and when the above file is dotted, bash
> complains about "Syntax error: Unexpected end of file" - as if
> it never seems the EOF tag.
>

I don't think so.  It doesn't see any command after the pipe
symbol (because the next and following lines are the here
document).  That's why GVIM shows the color used to indicate
strings and here documents.

> In the end, I ended up replacing the " << EOF | ANotherCommand
> ..." construct with:
>
>
> > >(ANotherCommand ...) << EOF
>
> and all is well. But why? Should this be necessary?
>

It isn't necessary, because there are at least three
alternatives.

> Yes, I know it is hard to debug this w/o specifics, but I really
> don't think the specifics matter; they would be hard to
> reproduce here.
>
>
> I just want to know if the basic syntax is valid and/or if there is a
> better workaround (better than switching to: > >(...))
>

Either use a backslash for unfolding a folded line (as Ben
showed) or put the part of the command line following the pipe
symbol ("|") after the EOF of the here document (as Janis showed)
or embrace the simple command and its here document by "{ ... ;
}":

{
someCommand -x -y "sjdfhk" and more options \
-g and still more options -Q "another option" << EOF
some data
for someCommand
EOF
} |
/usr/lib/ANotherCommand -x "with option" and "more options"

Subject: Re: Using << and an output pipe together in shell (bash)
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sun, 3 Nov 2024 23:49 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.unix.shell
Subject: Re: Using << and an output pipe together in shell (bash)
Date: Mon, 4 Nov 2024 00:49:14 +0100
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <vg925r$jcoe$1@dont-email.me>
References: <vg0q7d$3tlel$2@news.xmission.com>
<83ikt4vyto.fsf@helmutwaitzmann.news.arcor.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 04 Nov 2024 00:49:18 +0100 (CET)
Injection-Info: dont-email.me; posting-host="d8b3098fc2d942d6804e097c84b4fbcb";
logging-data="635662"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IKd/svoZbHyccfh3y0E+Q"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:cvGKguy++cZBFFbm3YdFBuuMgf0=
X-Enigmail-Draft-Status: N1110
In-Reply-To: <83ikt4vyto.fsf@helmutwaitzmann.news.arcor.de>
View all headers

On 03.11.2024 21:37, Helmut Waitzmann wrote:
> gazelle@shell.xmission.com (Kenny McCormack):
>>
>> I just want to know if the basic syntax is valid and/or if there is a
>> better workaround (better than switching to: > >(...))
>
> Either use a backslash for unfolding a folded line (as Ben
> showed) or put the part of the command line following the pipe
> symbol ("|") after the EOF of the here document (as Janis showed)
> or embrace the simple command and its here document by "{ ... ;
> }":
>
>
> {
> someCommand -x -y "sjdfhk" and more options \
> -g and still more options -Q "another option" << EOF
> some data
> for someCommand
> EOF
> } |
> /usr/lib/ANotherCommand -x "with option" and "more options"
>

In this vein (i.e. structuring the code) another option is to put
all these long commands with all their options into functions, so
that the complex command calls fit (with the pipes, and without
escapes) on a single line

f_someCommand <<EOF | f_anotherCommand
...
EOF

(This could make the code also better readable and maintainable.)

Janis

1

rocksolid light 0.9.8
clearnet tor