Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"This isn't brain surgery; it's just television." -- David Letterman


devel / comp.unix.shell / Re: Implicit String-Literal Concatenation

SubjectAuthor
* Re: Implicit String-Literal ConcatenationJanis Papanagnou
`* Re: Implicit String-Literal ConcatenationJanis Papanagnou
 `* Re: Implicit String-Literal ConcatenationChristian Weisgerber
  `* Re: Implicit String-Literal ConcatenationJanis Papanagnou
   `* Re: Implicit String-Literal ConcatenationChristian Weisgerber
    `* Re: Implicit String-Literal ConcatenationJanis Papanagnou
     `- Re: Implicit String-Literal ConcatenationChristian Weisgerber

1
Re: Implicit String-Literal Concatenation

<urlsgn$3fkrn$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7628&group=comp.unix.shell#7628

  copy link   Newsgroups: comp.lang.c comp.unix.shell
Followup: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: janis_papanagnou+ng@hotmail.com (Janis Papanagnou)
Newsgroups: comp.lang.c,comp.unix.shell
Subject: Re: Implicit String-Literal Concatenation
Followup-To: comp.unix.shell
Date: Wed, 28 Feb 2024 00:50:46 +0100
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <urlsgn$3fkrn$1@dont-email.me>
References: <urdsob$1e8e4$7@dont-email.me>
<1qf797ippluag.1p27j2yyk4ydt.dlg@40tude.net> <urisel$2nq9h$2@dont-email.me>
<urkjue$36npm$1@dont-email.me> <urlq4p$3ep9p$7@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 27 Feb 2024 23:50:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c4b9753b38fe667b839cfcc70e6edcca";
logging-data="3658615"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EkTj1FTYVo5jI7PTRUwRl"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:yDx2+fVDUg/8CWQcbmJZxJzuz80=
In-Reply-To: <urlq4p$3ep9p$7@dont-email.me>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Tue, 27 Feb 2024 23:50 UTC

On 28.02.2024 00:10, Lawrence D'Oliveiro wrote:
> On Tue, 27 Feb 2024 13:18:20 +0100, Janis Papanagnou wrote:
>
>> On 26.02.2024 21:31, Lawrence D'Oliveiro wrote:
>>>
>>> Question: How would you do two separate <<-strings in the same shell
>>> command?
>>
>> Can you give an example what you intend here? (With what semantics?)
>>
>> Since '<<' is redirecting the here-document text to stdin of the command
>> you can have only one channel.
>
> Perl lets you do something like
>
> func(<<EOD1, <<EOD2);
> ... contents of first string ...
> EOD1
> ... contents of second string ...
> EOD2
>
> But this doesn’t work in Bash. However, in a Posix shell, remember you can
> specify the number of the file descriptor you want to redirect, e.g.
>
> diff -u /dev/fd/8 /dev/fd/9 8<<'EOD1' 9<<'EOD2'
> ... contents of first string ...
> EOD1
> ... contents of second string ...
> EOD2
>
> Note I add the single quotes to prevent expansion of “$”-sequences within
> the strings. (I think this might be needed in Perl, too.)

I see. - Yes, you can do that in POSIX shells as well. - Note that I set
F'up-to CUS. And post the response there as a f'up to this post.

Janis

Re: Implicit String-Literal Concatenation

<urlt9a$3fpfj$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7629&group=comp.unix.shell#7629

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: Implicit String-Literal Concatenation
Date: Wed, 28 Feb 2024 01:03:52 +0100
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <urlt9a$3fpfj$1@dont-email.me>
References: <urdsob$1e8e4$7@dont-email.me>
<1qf797ippluag.1p27j2yyk4ydt.dlg@40tude.net> <urisel$2nq9h$2@dont-email.me>
<urkjue$36npm$1@dont-email.me> <urlq4p$3ep9p$7@dont-email.me>
<urlsgn$3fkrn$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 28 Feb 2024 00:03:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c4b9753b38fe667b839cfcc70e6edcca";
logging-data="3663347"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/CBd525Gb3XimNEcNlhwzA"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:OCAqRy3D83PO8jQvEhe0y0H0v4s=
In-Reply-To: <urlsgn$3fkrn$1@dont-email.me>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Wed, 28 Feb 2024 00:03 UTC

On 28.02.2024 00:50, Janis Papanagnou wrote:
> On 28.02.2024 00:10, Lawrence D'Oliveiro wrote:
>> On Tue, 27 Feb 2024 13:18:20 +0100, Janis Papanagnou wrote:
>>
>>> On 26.02.2024 21:31, Lawrence D'Oliveiro wrote:
>>>>
>>>> Question: How would you do two separate <<-strings in the same shell
>>>> command?
>>>
>>> Can you give an example what you intend here? (With what semantics?)
>>>
>>> Since '<<' is redirecting the here-document text to stdin of the command
>>> you can have only one channel.
>>
>> Perl lets you do something like
>>
>> func(<<EOD1, <<EOD2);
>> ... contents of first string ...
>> EOD1
>> ... contents of second string ...
>> EOD2
>>
>> But this doesn’t work in Bash. However, in a Posix shell, remember you can
>> specify the number of the file descriptor you want to redirect, e.g.
>>
>> diff -u /dev/fd/8 /dev/fd/9 8<<'EOD1' 9<<'EOD2'
>> ... contents of first string ...
>> EOD1
>> ... contents of second string ...
>> EOD2
>>
>> Note I add the single quotes to prevent expansion of “$”-sequences within
>> the strings. (I think this might be needed in Perl, too.)
>
> I see. - Yes, you can do that in POSIX shells as well. [...]

You found a syntactic solution already, but that requires some
non-standard /dev/fd OS support. Newer shells allow also process
substitution diff <(...) <(...) to support pipes where files
are expected, but that also relies on the existence of /dev/fd,
AFAICT.

With standard mechanisms when I want to read from two individual
stdin sources I do (for example) something like

exec 3<&0
while read <&3 ; read <&3 ; read <&3 # every 3rd line data #1
do echo $REPLY
read ; read ; echo $REPLY # every 2nd line data #2
done 3<<EOT1 <<EOT2
line 1
line 2
line 3
line 4
line 5
line 6
line 7
EOT1
line A
line B
line C
line D
line E
EOT2

With actually the same syntax at least for the here documents.

Otherwise, in your diff sample, use named pipes?

Janis

Re: Implicit String-Literal Concatenation

<slrnutujtc.kk2.naddy@lorvorc.mips.inka.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7630&group=comp.unix.shell#7630

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!rocksolid2!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: naddy@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell
Subject: Re: Implicit String-Literal Concatenation
Date: Wed, 28 Feb 2024 15:22:20 -0000 (UTC)
Message-ID: <slrnutujtc.kk2.naddy@lorvorc.mips.inka.de>
References: <urdsob$1e8e4$7@dont-email.me>
<1qf797ippluag.1p27j2yyk4ydt.dlg@40tude.net> <urisel$2nq9h$2@dont-email.me>
<urkjue$36npm$1@dont-email.me> <urlq4p$3ep9p$7@dont-email.me>
<urlsgn$3fkrn$1@dont-email.me> <urlt9a$3fpfj$1@dont-email.me>
Injection-Date: Wed, 28 Feb 2024 15:22:20 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="21123"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Christian Weisgerber - Wed, 28 Feb 2024 15:22 UTC

On 2024-02-28, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

> You found a syntactic solution already, but that requires some
> non-standard /dev/fd OS support. Newer shells allow also process
> substitution diff <(...) <(...) to support pipes where files
> are expected, but that also relies on the existence of /dev/fd,
> AFAICT.

Bash, at least, can alternatively use named pipes.
This is on FreeBSD:

bash$ cat s
#!/bin/sh
echo "$@"
ls -l "$@"

bash$ ./s <(echo hello)
/tmp//sh-np.Uawtgm
prw------- 1 naddy wheel 0 Feb 28 16:19 /tmp//sh-np.Uawtgm

--
Christian "naddy" Weisgerber naddy@mips.inka.de

Re: Implicit String-Literal Concatenation

<urnldn$3v5ud$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7631&group=comp.unix.shell#7631

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.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: Implicit String-Literal Concatenation
Date: Wed, 28 Feb 2024 17:01:58 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <urnldn$3v5ud$1@dont-email.me>
References: <urdsob$1e8e4$7@dont-email.me>
<1qf797ippluag.1p27j2yyk4ydt.dlg@40tude.net> <urisel$2nq9h$2@dont-email.me>
<urkjue$36npm$1@dont-email.me> <urlq4p$3ep9p$7@dont-email.me>
<urlsgn$3fkrn$1@dont-email.me> <urlt9a$3fpfj$1@dont-email.me>
<slrnutujtc.kk2.naddy@lorvorc.mips.inka.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 28 Feb 2024 16:01:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="466c528f7b0b6fde24aa04143326743b";
logging-data="4167629"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5IsRISJsW38O12z5B9+Pv"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:xiW2tRQ7Z2Z8c0f4AisbZDG/EKk=
In-Reply-To: <slrnutujtc.kk2.naddy@lorvorc.mips.inka.de>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Wed, 28 Feb 2024 16:01 UTC

On 28.02.2024 16:22, Christian Weisgerber wrote:
> On 2024-02-28, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>
>> You found a syntactic solution already, but that requires some
>> non-standard /dev/fd OS support. Newer shells allow also process
>> substitution diff <(...) <(...) to support pipes where files
>> are expected, but that also relies on the existence of /dev/fd,
>> AFAICT.
>
> Bash, at least, can alternatively use named pipes.

Yes, below you're using newer shells' process substitution (as I
also did above). It implicitly requires an OS supporting /dev/fd .

The original poster (from comp.lang.c) used also a /dev/fd based
version like this
diff -u /dev/fd/8 /dev/fd/9 8<<'EOD1' 9<<'EOD2'
which appears overly complicated and it's explicitly also relying
on /dev/fd .

> This is on FreeBSD:
>
> bash$ cat s
> #!/bin/sh
> echo "$@"
> ls -l "$@"
>
> bash$ ./s <(echo hello)
> /tmp//sh-np.Uawtgm
> prw------- 1 naddy wheel 0 Feb 28 16:19 /tmp//sh-np.Uawtgm
>

With the OP's original question:
>>> Question: How would you do two separate <<-strings in the same
>>> shell command?
it would be interesting to see some neat solution that does not
rely implicitly (by process substitution) or explicitly on /dev/fd .

The OP gave an example how it can be done in Perl:
func(<<EOD1, <<EOD2);
... contents of first string ...
EOD1
... contents of second string ...
EOD2
and is probably seeking a terse alternative in shell.

Janis

Re: Implicit String-Literal Concatenation

<slrnututro.o89.naddy@lorvorc.mips.inka.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7632&group=comp.unix.shell#7632

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!news.nntp4.net!weretis.net!feeder8.news.weretis.net!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: naddy@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell
Subject: Re: Implicit String-Literal Concatenation
Date: Wed, 28 Feb 2024 18:12:08 -0000 (UTC)
Message-ID: <slrnututro.o89.naddy@lorvorc.mips.inka.de>
References: <urdsob$1e8e4$7@dont-email.me>
<1qf797ippluag.1p27j2yyk4ydt.dlg@40tude.net> <urisel$2nq9h$2@dont-email.me>
<urkjue$36npm$1@dont-email.me> <urlq4p$3ep9p$7@dont-email.me>
<urlsgn$3fkrn$1@dont-email.me> <urlt9a$3fpfj$1@dont-email.me>
<slrnutujtc.kk2.naddy@lorvorc.mips.inka.de> <urnldn$3v5ud$1@dont-email.me>
Injection-Date: Wed, 28 Feb 2024 18:12:08 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="24842"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Christian Weisgerber - Wed, 28 Feb 2024 18:12 UTC

On 2024-02-28, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

>> Bash, at least, can alternatively use named pipes.
>
> Yes, below you're using newer shells' process substitution (as I
> also did above). It implicitly requires an OS supporting /dev/fd .

It does not! That was my point. Bash implements process substitution
with temporary named pipes on systems where /dev/fd/* may not be
available:

>> bash$ ./s <(echo hello)
>> /tmp//sh-np.Uawtgm
>> prw------- 1 naddy wheel 0 Feb 28 16:19 /tmp//sh-np.Uawtgm

--
Christian "naddy" Weisgerber naddy@mips.inka.de

Re: Implicit String-Literal Concatenation

<urol87$5s0p$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7633&group=comp.unix.shell#7633

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: Implicit String-Literal Concatenation
Date: Thu, 29 Feb 2024 02:05:10 +0100
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <urol87$5s0p$1@dont-email.me>
References: <urdsob$1e8e4$7@dont-email.me>
<1qf797ippluag.1p27j2yyk4ydt.dlg@40tude.net> <urisel$2nq9h$2@dont-email.me>
<urkjue$36npm$1@dont-email.me> <urlq4p$3ep9p$7@dont-email.me>
<urlsgn$3fkrn$1@dont-email.me> <urlt9a$3fpfj$1@dont-email.me>
<slrnutujtc.kk2.naddy@lorvorc.mips.inka.de> <urnldn$3v5ud$1@dont-email.me>
<slrnututro.o89.naddy@lorvorc.mips.inka.de>
MIME-Version: 1.0
Content-Type: text/plain; charset=windows-1252
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 29 Feb 2024 01:05:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b6b7dfb14cc23b99cfa8f4ac3d9b7593";
logging-data="192537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iNrQG82uBW5rtepYoPHLY"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:1Z+fULML0tlttSSHBfvqQpXJQ54=
In-Reply-To: <slrnututro.o89.naddy@lorvorc.mips.inka.de>
X-Enigmail-Draft-Status: N1110
 by: Janis Papanagnou - Thu, 29 Feb 2024 01:05 UTC

On 28.02.2024 19:12, Christian Weisgerber wrote:
> On 2024-02-28, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
>>
>> Yes, below you're using newer shells' process substitution (as I
>> also did above). It implicitly requires an OS supporting /dev/fd .
>
> It does not! That was my point. Bash implements process substitution
> with temporary named pipes on systems where /dev/fd/* may not be
> available:

That's interesting! And you are right; the bash man page indeed says:
"Process substitution is supported on systems that support
named pipes (FIFOs) or the /dev/fd method of naming open
files."

The Bolsky/Korn Kornshell book says that Kornshell supports process
substitution on Unix systems that support /dev/fd/ and I'd have
expected that Bash adopted that from Kornshell (as it did with so
many Kornshell features). But probably not...

Or does Kornshell also support it independently of /dev/fd/ also
with named pipes? (I cannot check that on my system.)

Janis

Re: Implicit String-Literal Concatenation

<slrnuu4f08.2iip.naddy@lorvorc.mips.inka.de>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=7634&group=comp.unix.shell#7634

  copy link   Newsgroups: comp.unix.shell
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!feeder8.news.weretis.net!news.szaf.org!inka.de!mips.inka.de!.POSTED.localhost!not-for-mail
From: naddy@mips.inka.de (Christian Weisgerber)
Newsgroups: comp.unix.shell
Subject: Re: Implicit String-Literal Concatenation
Date: Fri, 1 Mar 2024 20:35:20 -0000 (UTC)
Message-ID: <slrnuu4f08.2iip.naddy@lorvorc.mips.inka.de>
References: <urdsob$1e8e4$7@dont-email.me>
<1qf797ippluag.1p27j2yyk4ydt.dlg@40tude.net> <urisel$2nq9h$2@dont-email.me>
<urkjue$36npm$1@dont-email.me> <urlq4p$3ep9p$7@dont-email.me>
<urlsgn$3fkrn$1@dont-email.me> <urlt9a$3fpfj$1@dont-email.me>
<slrnutujtc.kk2.naddy@lorvorc.mips.inka.de> <urnldn$3v5ud$1@dont-email.me>
<slrnututro.o89.naddy@lorvorc.mips.inka.de> <urol87$5s0p$1@dont-email.me>
Injection-Date: Fri, 1 Mar 2024 20:35:20 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="84570"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
 by: Christian Weisgerber - Fri, 1 Mar 2024 20:35 UTC

On 2024-02-29, Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:

> The Bolsky/Korn Kornshell book says that Kornshell supports process
> substitution on Unix systems that support /dev/fd/ and I'd have
> expected that Bash adopted that from Kornshell (as it did with so
> many Kornshell features). But probably not...

> Or does Kornshell also support it independently of /dev/fd/ also
> with named pipes? (I cannot check that on my system.)

Checking the nearest available ksh93 source, I see:

#### COMPILE-TIME OPTIONS ####

....
DEVFD Use the more secure /dev/fd mechanism instead of FIFOs for
process substitutions. On by default on OSs with /dev/fd.
....

--
Christian "naddy" Weisgerber naddy@mips.inka.de

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor