Rocksolid Light

News from da outaworlds

mail  files  register  groups  login

Message-ID:  

You are dishonest, but never to the point of hurting a friend.


comp / comp.unix.shell / Re: Different variable assignments

SubjectAuthor
* Different variable assignmentsFrank Winkler
+* Re: Different variable assignmentsJohn-Paul Stewart
|`* Re: Different variable assignmentsFrank Winkler
| `* Re: Different variable assignmentsJanis Papanagnou
|  +* Re: Different variable assignmentsLawrence D'Oliveiro
|  |`* Re: Different variable assignmentsKenny McCormack
|  | `* Re: Different variable assignmentsJanis Papanagnou
|  |  `* coprocs in bash & ksh (Was: Different variable assignments)Kenny McCormack
|  |   `- Re: coprocs in bash & ksh (Was: Different variable assignments)Janis Papanagnou
|  +* Re: Different variable assignmentsFrank Winkler
|  |+- Re: Different variable assignmentsLawrence D'Oliveiro
|  |`* Re: Different variable assignmentsJanis Papanagnou
|  | +* Re: Different variable assignmentsLem Novantotto
|  | |`* Re: Different variable assignmentsFrank Winkler
|  | | +* Re: Different variable assignmentsLem Novantotto
|  | | |`* lastpipe (Was: Different variable assignments)Kenny McCormack
|  | | | `- Re: lastpipe (Was: Different variable assignments)Lem Novantotto
|  | | +* Re: Different variable assignmentsLawrence D'Oliveiro
|  | | |`* Re: Different variable assignmentsJanis Papanagnou
|  | | | `* Re: Different variable assignmentsLawrence D'Oliveiro
|  | | |  `- Re: Different variable assignmentsJanis Papanagnou
|  | | +* Re: Different variable assignmentsLem Novantotto
|  | | |+- Re: Different variable assignmentsLem Novantotto
|  | | |`- Re: Different variable assignmentsLem Novantotto
|  | | `* Re: Different variable assignmentsFrank Winkler
|  | |  `* Re: Different variable assignmentsFrank Winkler
|  | |   +* Re: Different variable assignmentsKenny McCormack
|  | |   |`* Re: Different variable assignmentsFrank Winkler
|  | |   | `- Re: Different variable assignmentsJanis Papanagnou
|  | |   `* Re: Different variable assignmentsLem Novantotto
|  | |    `* tee with no args is a no-op (Was: Different variable assignments)Kenny McCormack
|  | |     `- Re: tee with no args is a no-op (Was: Different variable assignments)Lem Novantotto
|  | `- Re: Different variable assignmentsFrank Winkler
|  `- lastpipe (Was: Different variable assignments)Kenny McCormack
`* Re: Different variable assignmentsHelmut Waitzmann
 +* Re: Different variable assignmentsFrank Winkler
 |+* Re: Different variable assignmentsLawrence D'Oliveiro
 ||`* Re: Different variable assignmentsKenny McCormack
 || `* Re: Different variable assignmentsJanis Papanagnou
 ||  +* coproc or whatever in bash and ksh (Was: Different variable assignments)Kenny McCormack
 ||  |`* Re: coproc or whatever in bash and ksh (Was: Different variable assignments)Janis Papanagnou
 ||  | +- Re: coproc or whatever in bash and ksh (Was: Different variable assignments)Janis Papanagnou
 ||  | `- Re: coproc or whatever in bash and ksh (Was: Different variable assignments)Kenny McCormack
 ||  `* Re: Different variable assignmentsLawrence D'Oliveiro
 ||   `* Re: Different variable assignmentsKenny McCormack
 ||    `* Re: Different variable assignmentsJanis Papanagnou
 ||     `* coprocs - again (Was: Different variable assignments)Kenny McCormack
 ||      `* Re: coprocs - again (Was: Different variable assignments)Janis Papanagnou
 ||       +* Re: coprocs - again (Was: Different variable assignments)Lawrence D'Oliveiro
 ||       |+* Re: coprocs - again (Was: Different variable assignments)Janis Papanagnou
 ||       ||`* Subjective "valuations" are all we have (Was: coprocs - again (Was: Different vaKenny McCormack
 ||       || `* Re: Subjective "valuations" are all we have (Was: coprocs - againJanis Papanagnou
 ||       ||  +- Re: Subjective "valuations" are all we have (Was: coprocs - againLem Novantotto
 ||       ||  `* Re: Subjective "valuations" are all we have (Was: coprocs - againKenny McCormack
 ||       ||   `- Re: Subjective "valuations" are all we have (Was: coprocs - againJanis Papanagnou
 ||       |`- Re: coprocs - again (Was: Different variable assignments)Kenny McCormack
 ||       `- How to do multiple concurrent coprocs in ksh (Was: coprocs - again (Was: DiffereKenny McCormack
 |`- Re: Different variable assignmentsChristian Weisgerber
 `* Re: Different variable assignmentsKenny McCormack
  `- Re: Different variable assignmentsLem Novantotto

Pages:123
Subject: Different variable assignments
From: Frank Winkler
Newsgroups: comp.unix.shell
Date: Fri, 11 Oct 2024 18:11 UTC
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@f.winkler-ka.de (Frank Winkler)
Newsgroups: comp.unix.shell
Subject: Different variable assignments
Date: Fri, 11 Oct 2024 20:11:57 +0200
Lines: 39
Message-ID: <lmt83dFsvbvU3@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net QNGSxFez8CHkoALEVk0NRgiJ4qHwp7mDFrL4oJDiVda7ahsbLe
Cancel-Lock: sha1:m4lPI7FhJb726WCHY0lXLM7sPQQ= sha256:8E1vvSVrzIFB8b/wM7/I+Iq8PElVUjDGDaMEzpPaYIw=
User-Agent: Mozilla Thunderbird Beta
Content-Language: en-US
View all headers

Hi there !

Consider the following commands:

$ var1=`uname -sr`
$ echo $var1
Darwin 24.0.0
$ read var2 <<< `uname -sr`
$ echo $var2
Darwin 24.0.0
$ uname -sr | read var3
$ echo $var3

$ uname -sr | read -p var3
$ echo $var3

$

While the first two ones behave like expected, I wonder why the latter
ones fail. What's the difference behind the scenes?

And even more confusing, why does this familiar one work anyway?

$ sw_vers | while read line; do echo $line; done
ProductName: macOS
ProductVersion: 15.0.1
BuildVersion: 24A348
$

I've been using commands like that one for a very long time and that's
why I tried the simple "read" above - with no success.

How can I do such an assignment at the end of a command instead of the
beginning? Any ideas?

TIA

fw

Subject: Re: Different variable assignments
From: John-Paul Stewart
Newsgroups: comp.unix.shell
Date: Fri, 11 Oct 2024 18:27 UTC
References: 1
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: jpstewart@personalprojects.net (John-Paul Stewart)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Fri, 11 Oct 2024 14:27:40 -0400
Lines: 37
Message-ID: <lmt90sFr1idU1@mid.individual.net>
References: <lmt83dFsvbvU3@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
X-Trace: individual.net cQmIxTZSfFl/1dPNzG/hZw+datNFiQ4nR60p8IT4yQtx+myddj
Cancel-Lock: sha1:OsEfW7x05w2G7/HjYGFQgCKHJTw= sha256:o9QA/pjwWX5YptPk3EpXah9i+xDx4jDhzq531WFCzKk=
User-Agent: Mozilla Thunderbird
Content-Language: en-CA
In-Reply-To: <lmt83dFsvbvU3@mid.individual.net>
View all headers

On 2024-10-11 2:11 p.m., Frank Winkler wrote:
> Hi there !
>
> Consider the following commands:
>
>
> $ var1=`uname -sr`
> $ echo $var1
> Darwin 24.0.0
> $ read var2 <<< `uname -sr`
> $ echo $var2
> Darwin 24.0.0
> $ uname -sr | read var3
> $ echo $var3
>
> $ uname -sr | read -p var3
> $ echo $var3
>
> $
>
> While the first two ones behave like expected, I wonder why the latter
> ones fail. What's the difference behind the scenes?

I don't know about other shells, but in Bash each command in a pipeline
is run in a subshell. (See the "Pipelines" section of the Bash man
page.) Thus you're doing the 'read var3' part in a different shell than
where 'echo $var3' runs. That's why it is empty when you echo it.

> And even more confusing, why does this familiar one work anyway?
>
> $ sw_vers | while read line; do echo $line; done
> ProductName: macOS
> ProductVersion: 15.0.1
> BuildVersion: 24A348

Here the subshell runs everything between 'while' and 'done' so the read
and echo commands are in the same (sub)shell this time.

Subject: Re: Different variable assignments
From: Frank Winkler
Newsgroups: comp.unix.shell
Date: Fri, 11 Oct 2024 18:45 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@f.winkler-ka.de (Frank Winkler)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Fri, 11 Oct 2024 20:45:07 +0200
Lines: 15
Message-ID: <lmta1jFsvc0U1@mid.individual.net>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net bg4cWIE2Xs9Fm81KLz2QqAiZZghrHck2BZYtSmJm2SGF0wYRqK
Cancel-Lock: sha1:EGv9RcbLxbBOwoQ/73qCCODoOls= sha256:xuP0+gAgAALXC6KxVTICQVtTPBXsGiuq9zV59xTdE2w=
User-Agent: Mozilla Thunderbird Beta
Content-Language: en-US
In-Reply-To: <lmt90sFr1idU1@mid.individual.net>
View all headers

On 11.10.2024 20:27, John-Paul Stewart wrote:

>I don't know about other shells, but in Bash each command in a pipeline
>is run in a subshell. (See the "Pipelines" section of the Bash man
>page.) Thus you're doing the 'read var3' part in a different shell than
>where 'echo $var3' runs. That's why it is empty when you echo it.

That sounds very plausible - thanks for enlighting! :)
So this is not a "read" issue but rather a matter of shell instance and
hence there's no way to do the assignment at the end?

Regards

fw

Subject: Re: Different variable assignments
From: Helmut Waitzmann
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Fri, 11 Oct 2024 20:20 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: Different variable assignments
Date: Fri, 11 Oct 2024 22:20:26 +0200
Organization: A noiseless patient Spider
Lines: 45
Sender: Helmut Waitzmann <12f7e638@mail.de>
Message-ID: <83y12u2xyt.fsf@helmutwaitzmann.news.arcor.de>
References: <lmt83dFsvbvU3@mid.individual.net>
Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
MIME-Version: 1.0
Content-Type: text/plain; format=flowed
Content-Transfer-Encoding: quoted-printable
Injection-Date: Fri, 11 Oct 2024 22:28:49 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="3dc4789b0500aa0566d9de3b31dd1f51";
logging-data="3995309"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18OdzGvbOgG0OyJjuVhtU5Kw5F/GBBQpMU="
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
Cancel-Lock: sha1:2Rq8XujY1t3nLrrgdGMdZduhkKc=
sha1:JVNDkGeJo1RDE+He8+d+JBwqOqk=
Mail-Copies-To: nobody
Mail-Reply-To: Helmut Waitzmann Anti-Spam-Ticket.b.qc3c <oe.throttle@xoxy.net>
View all headers

Frank Winkler <usenet@f.winkler-ka.de>:
> Hi there !
>
>
> Consider the following commands:
>
>
>
> $ var1=`uname -sr`
> $ echo $var1
> Darwin 24.0.0
> $ read var2 <<< `uname -sr`
> $ echo $var2
> Darwin 24.0.0
> $ uname -sr | read var3
> $ echo $var3
>
> $ uname -sr | read -p var3
> $ echo $var3
>
> $
>
> While the first two ones behave like expected, I wonder why the
> latter ones fail. What's the difference behind the scenes?
>
>
> And even more confusing, why does this familiar one work anyway?
>
>
> $ sw_vers | while read line; do echo $line; done
> ProductName: macOS
> ProductVersion: 15.0.1
> BuildVersion: 24A348
> $
>
> I've been using commands like that one for a very long time and
> that's why I tried the simple "read" above - with no success.
>
>
> How can I do such an assignment at the end of a command instead
> of the beginning? Any ideas?
>

uname -sr | { read var3 ; echo $var3 ; }

Subject: Re: Different variable assignments
From: Frank Winkler
Newsgroups: comp.unix.shell
Date: Fri, 11 Oct 2024 20:50 UTC
References: 1 2
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@f.winkler-ka.de (Frank Winkler)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Fri, 11 Oct 2024 22:50:10 +0200
Lines: 17
Message-ID: <lmthc2F9kfU1@mid.individual.net>
References: <lmt83dFsvbvU3@mid.individual.net>
<83y12u2xyt.fsf@helmutwaitzmann.news.arcor.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net Erc5tM2mif6tmMZkvsx+GgLcVRtcusy+tjYT+HDGSfiKKYbeYl
Cancel-Lock: sha1:idgIcoobeJBy2sJOt5uQbUj2KLo= sha256:MTN9fkCQ7Nmya58OfMUQdT7ZL8gKyG2QXY+LvoBWvLI=
User-Agent: Mozilla Thunderbird Beta
Content-Language: en-US
In-Reply-To: <83y12u2xyt.fsf@helmutwaitzmann.news.arcor.de>
View all headers

On 11.10.2024 22:20, Helmut Waitzmann wrote:

> uname -sr | { read var3 ; echo $var3 ; }

That's exactly how I just wanted to confirm John-Paul's answer ...

$ uname -sr | ( read var3; echo $var3 )
Darwin 24.0.0
$

.... but it still doesn't solve the issue that I need the result to be
visible in the parent shell.

Regards

fw

Subject: Re: Different variable assignments
From: Lawrence D'Oliv
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Fri, 11 Oct 2024 21:03 UTC
References: 1 2 3
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Fri, 11 Oct 2024 21:03:07 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <vec3qb$3q4ms$3@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<83y12u2xyt.fsf@helmutwaitzmann.news.arcor.de>
<lmthc2F9kfU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 11 Oct 2024 23:03:08 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="0b5f06eee4a1d884280520d20084135c";
logging-data="4002524"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xF5dY8FZ/g3T8Ah2YhS88"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:e082SdO089kR2w7jieqDFfDqioY=
View all headers

On Fri, 11 Oct 2024 22:50:10 +0200, Frank Winkler wrote:

> ... but it still doesn't solve the issue that I need the result to be
> visible in the parent shell.

coproc { uname -sr; }
read -u ${COPROC[0]} var3
wait $COPROC_PID
echo $var3

Subject: Re: Different variable assignments
From: Christian Weisgerber
Newsgroups: comp.unix.shell
Date: Fri, 11 Oct 2024 23:25 UTC
References: 1 2 3
Path: eternal-september.org!news.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: Different variable assignments
Date: Fri, 11 Oct 2024 23:25:39 -0000 (UTC)
Message-ID: <slrnvgjcvj.2cra.naddy@lorvorc.mips.inka.de>
References: <lmt83dFsvbvU3@mid.individual.net>
<83y12u2xyt.fsf@helmutwaitzmann.news.arcor.de>
<lmthc2F9kfU1@mid.individual.net>
Injection-Date: Fri, 11 Oct 2024 23:25:39 -0000 (UTC)
Injection-Info: lorvorc.mips.inka.de; posting-host="localhost:::1";
logging-data="78699"; mail-complaints-to="usenet@mips.inka.de"
User-Agent: slrn/1.0.3 (FreeBSD)
View all headers

On 2024-10-11, Frank Winkler <usenet@f.winkler-ka.de> wrote:

> $ uname -sr | ( read var3; echo $var3 )
> Darwin 24.0.0
> $
>
> ... but it still doesn't solve the issue that I need the result to be
> visible in the parent shell.

read var3 <<EOF
$(uname -sr)
EOF
echo "$var3"

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

Subject: Re: Different variable assignments
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 01:59 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: Different variable assignments
Date: Sat, 12 Oct 2024 03:59:49 +0200
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <vecl6n$d0r$1@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 12 Oct 2024 03:59:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1bb6ba8d9a0743d0ec7c52c2bf248c5a";
logging-data="13339"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX185ehMDODX6p57OjYZ04uwd"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:NqbSfSnL7r3nvIGwGDL1Kh4VqP4=
In-Reply-To: <lmta1jFsvc0U1@mid.individual.net>
X-Enigmail-Draft-Status: N1110
View all headers

On 11.10.2024 20:45, Frank Winkler wrote:
> On 11.10.2024 20:27, John-Paul Stewart wrote:
>
> >I don't know about other shells, but in Bash each command in a pipeline
> >is run in a subshell. (See the "Pipelines" section of the Bash man
> >page.) Thus you're doing the 'read var3' part in a different shell than
> >where 'echo $var3' runs. That's why it is empty when you echo it.
>
> That sounds very plausible - thanks for enlighting! :)

> So this is not a "read" issue but rather a matter of shell instance and
> hence there's no way to do the assignment at the end?

It depends on your shell. If you choose Kornshell you won't have that
issue and can write it as you've done with the output as you'd expect.

$ uname -a | read var
$ echo "$var"
Linux [...snip...]

The reason is that the last command in a pipeline will (in Kornshell)
be executed in the "current" shell context.

(In other shells you have to work around the issue as demonstrated in
other answers to your post. Some workaround are more clumsy some less.
A shorter variant of the here-document posted elsethread can be using
here-strings

$ read var <<< $(uname -a)

another method is using process substitution and redirection

$ read var < <(uname -a)

Both supported by shells like ksh, bash, zsh, but non-standard as are
some other workaround proposals that use bash-specifics like 'coproc',
that doesn't work as widely as using '<<<' or '<(...)' do.)

Janis

Subject: Re: Different variable assignments
From: Lawrence D'Oliv
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 02:26 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 02:26:44 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 5
Message-ID: <vecmp3$pur$1@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Oct 2024 04:26:44 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c5355a95aaf967e5c35c649cc5a0b328";
logging-data="26587"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19otxglMsW69clGF23NS4QQ"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:D3OvXJ+irR+pgH4Bwpeo/iVWUP4=
View all headers

On Sat, 12 Oct 2024 03:59:49 +0200, Janis Papanagnou wrote:

> ... use bash-specifics like 'coproc' ...

It isn’t bash-specific.

Subject: Re: Different variable assignments
From: Frank Winkler
Newsgroups: comp.unix.shell
Date: Sat, 12 Oct 2024 07:42 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@f.winkler-ka.de (Frank Winkler)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 09:42:22 +0200
Lines: 49
Message-ID: <lmuniuF632tU1@mid.individual.net>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net A31PnurH41JGq3JNPbT60gSef0mnT7TkX183PTNtJbIQxmPWIB
Cancel-Lock: sha1:zu+eU2Ki/AmTsdb+CanBVBVuB0U= sha256:kqMuyP9RwcLAT6cI+3w3ltGrdtRqlgAkWxUOM0IQZN8=
User-Agent: Mozilla Thunderbird Beta
Content-Language: en-US
In-Reply-To: <vecl6n$d0r$1@dont-email.me>
View all headers

On 12.10.2024 03:59, Janis Papanagnou wrote:

>It depends on your shell. If you choose Kornshell you won't have that
>issue and can write it as you've done with the output as you'd expect.
>
>$ uname -a | read var
>$ echo "$var"
>Linux [...snip...]
>
>The reason is that the last command in a pipeline will (in Kornshell)
>be executed in the "current" shell context.

Interesting hint! I wasn't aware that there are such differences between
the shells. And indeed, some simple tests seem to work in an interactive
ksh.

Let's see the whole story. For historical reasons, I'm actually using
ksh for almost all scripts instead of bash for interactive use - not
knowing about the fact above.

There, I run command A which is producing output and which is calling
sub-command B, also producing output. This works fine.
What I want to achieve is to grab some parts of the output and store it
in a variable but without changing the output on the screen.

So I tried something like

tty=`tty`
A | tee $tty | ... | read var

"tee `tty`" inside the command fails, so I do it outside. The output of
A is still there but B's is gone (because B doesn't know anything about
the "tee"?) and the whole thing doesn't seem to be still working. $var
is empty, though this is a ksh script and the stuff behind "tee" is also
working.
To my understanding, the default B can be changed with an option but
when I set it to "B | tee $tty", there's still no output.

AFAIR, "var=`...`" works better but as the primary job is the command
itself and the variable is just a spin-off product, I'd prefer to do the
assignment at the end. I believe it looks better then ;) ...

Probably it would also be feasible with some temp files but I try to
avoid them wherever possible.

Happy week-end!

fw

Subject: Re: Different variable assignments
From: Lawrence D'Oliv
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 07:51 UTC
References: 1 2 3 4 5
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 07:51:47 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <ved9qj$36uf$5@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Oct 2024 09:51:47 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c5355a95aaf967e5c35c649cc5a0b328";
logging-data="105423"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qMnDkSvgg0tAM3P82Xfev"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:M+1GcLrsWKUQ8n18hrcLk/koUqI=
View all headers

On Sat, 12 Oct 2024 09:42:22 +0200, Frank Winkler wrote:

> AFAIR, "var=`...`" works ...

POSIX also allows

$(«cmd»)

as a nicer alternative to

`«cmd»`

Subject: Re: Different variable assignments
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 11:08 UTC
References: 1 2 3 4 5
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: Different variable assignments
Date: Sat, 12 Oct 2024 13:08:48 +0200
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <vedlc2$4vi6$1@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 12 Oct 2024 13:08:51 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="1bb6ba8d9a0743d0ec7c52c2bf248c5a";
logging-data="163398"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+KULTGmSz+aZPXdrL3yVpZ"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:czeosVGXXyffePCAQcz7bTeh1T4=
In-Reply-To: <lmuniuF632tU1@mid.individual.net>
X-Enigmail-Draft-Status: N1110
View all headers

On 12.10.2024 09:42, Frank Winkler wrote:
> On 12.10.2024 03:59, Janis Papanagnou wrote:
>
> >It depends on your shell. If you choose Kornshell you won't have that
> >issue and can write it as you've done with the output as you'd expect.
> >
> >$ uname -a | read var
> >$ echo "$var"
> >Linux [...snip...]
> >
> >The reason is that the last command in a pipeline will (in Kornshell)
> >be executed in the "current" shell context.
>
> Interesting hint! I wasn't aware that there are such differences between
> the shells.

Yes, it's a subtle difference, but an important one; many shell users
wondered about the behavior of other shells, and you need to know the
internal information about subprocesses used in pipes to understand
why it doesn't work (in other shells), or why it does in ksh.

> And indeed, some simple tests seem to work in an interactive
> ksh.

You can rely on it with any official ksh (since ksh88) and branches of
them. (But don't count on it if you're using some inferior ksh clone.)

>
> Let's see the whole story. For historical reasons, I'm actually using
> ksh for almost all scripts instead of bash for interactive use - not
> knowing about the fact above.

From your description below I'm not sure you still have a question or
whether you're just describing what you intended to do and are fine
with ksh's pipeline behavior. (Specifically I'm unsure about the 'B'
and what you mean by "sub-command B" in your example(s).)

If something is still not working for you, please clarify.

>
> There, I run command A which is producing output and which is calling
> sub-command B, also producing output. This works fine.
> What I want to achieve is to grab some parts of the output and store it
> in a variable but without changing the output on the screen.
>
> So I tried something like
>
> tty=`tty`
> A | tee $tty | ... | read var

$ man tty
tty - print the file name of the terminal connected to standard input

The 'tty' command in your 'tee' pipeline command has no tty attached;
it reads from the pipe. That's why A | tee $(tty) | ... | read var
doesn't work as you expected. You have to grab the tty information
outside the pipeline (as you've experienced).

Janis

>
> "tee `tty`" inside the command fails, so I do it outside. The output of
> A is still there but B's is gone (because B doesn't know anything about
> the "tee"?) and the whole thing doesn't seem to be still working. $var
> is empty, though this is a ksh script and the stuff behind "tee" is also
> working.
> To my understanding, the default B can be changed with an option but
> when I set it to "B | tee $tty", there's still no output.
>
> AFAIR, "var=`...`" works better but as the primary job is the command
> itself and the variable is just a spin-off product, I'd prefer to do the
> assignment at the end. I believe it looks better then ;) ...
>
> Probably it would also be feasible with some temp files but I try to
> avoid them wherever possible.
>
> Happy week-end!
>
> fw
>

Subject: Re: Different variable assignments
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 12:01 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 12:01:55 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <vedofj$5g3v$1@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Oct 2024 14:01:56 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="fb953ca9d31e98c34c2436e63d685284";
logging-data="180351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ch+HEPCP2/u8yryHWof/XNd9hC88NFJ4="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:OihO1vDS6v7KBQHP/E+kMYPoZMI=
View all headers

Il Sat, 12 Oct 2024 13:08:48 +0200, Janis Papanagnou ha scritto:

> (Specifically I'm unsure about the 'B' and what you mean by "sub-command
> B" in your example(s).)

Waiting for his clarification, I'm thinking that he sees that something
like:

$ input=$(tty) && echo 123456789 | tee $input | grep -o 456 | \
> tee $input | read myvar && echo "myvar is $myvar"; input= ; myvar=
123456789
456
myvar is

doesn't work, while of course:

$ input=$(tty) && read myvar < <( echo 123456789 | tee $input | \
> grep -o 456 | tee $input ) && echo "myvar is $myvar"; input= ; myvar=
123456789
456
myvar is 456

does work (BTW: here I'm in Bash).
--
Bye, Lem

Subject: Re: Different variable assignments
From: Frank Winkler
Newsgroups: comp.unix.shell
Date: Sat, 12 Oct 2024 15:49 UTC
References: 1 2 3 4 5 6
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@f.winkler-ka.de (Frank Winkler)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 17:49:55 +0200
Lines: 22
Message-ID: <lmvk53F860uU1@mid.individual.net>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net MGqCotBeqnD4sMnAvcdscwfXIHnUsKQ0joguPIs2imV0wVuYRE
Cancel-Lock: sha1:/TClmwm1owzUmgGolzkp3KsF9jU= sha256:0xWRVXiX7fwnyb5GXhKUOTSGE3kEG+/bW30kTg6zgYQ=
User-Agent: Mozilla Thunderbird Beta
Content-Language: en-US
In-Reply-To: <vedlc2$4vi6$1@dont-email.me>
View all headers

On 12.10.2024 13:08, Janis Papanagnou wrote:

>From your description below I'm not sure you still have a question or
>whether you're just describing what you intended to do and are fine
>with ksh's pipeline behavior. (Specifically I'm unsure about the 'B'
>and what you mean by "sub-command B" in your example(s).)

A spawns B and grabbing the desired information from the common output
still doesn't work.

>The 'tty' command in your 'tee' pipeline command has no tty attached;
>it reads from the pipe. That's why A | tee $(tty) | ... | read var
>doesn't work as you expected. You have to grab the tty information
>outside the pipeline (as you've experienced).

That was also my understanding after the experience ;) ... but thanks
for confirmation.

Regards

fw

Subject: Re: Different variable assignments
From: Frank Winkler
Newsgroups: comp.unix.shell
Date: Sat, 12 Oct 2024 15:57 UTC
References: 1 2 3 4 5 6 7
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@f.winkler-ka.de (Frank Winkler)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 17:57:16 +0200
Lines: 34
Message-ID: <lmvkisF860uU2@mid.individual.net>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 4B/Vr3IVvSDc5Y4dgHaV8gSp/SeS3b7U7eGFvE4CG0+Aq3gs5W
Cancel-Lock: sha1:BRZOYfcOzC8kQHScXO0l1IHD8bE= sha256:E+X8IL30N41B6DZuA9G9+RMi9wO5Mu74Ngfhe+bmZQg=
User-Agent: Mozilla Thunderbird Beta
Content-Language: en-US
In-Reply-To: <vedofj$5g3v$1@dont-email.me>
View all headers

On 12.10.2024 14:01, Lem Novantotto wrote:

>Waiting for his clarification, I'm thinking that he sees that something
>like:
>
>$ input=$(tty) && echo 123456789 | tee $input | grep -o 456 | \
> tee $input | read myvar && echo "myvar is $myvar"; input= ; myvar=
>123456789
>456
>myvar is
>
>doesn't work

I think you're right. But why doesn't it work in ksh?

> while of course:
>
>$ input=$(tty) && read myvar < <( echo 123456789 | tee $input | \
> grep -o 456 | tee $input ) && echo "myvar is $myvar"; input= ; myvar=
>123456789
>456
>myvar is 456
>
>does work (BTW: here I'm in Bash).

I'm still thinking about the difference between "< <(...)" and "<<< `...`"

And I would be happy with this one if there was a notation "the other
way round" ;) ... something like "... >>> $var"

Regards

fw

Subject: Re: Different variable assignments
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 17:09 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 17:09:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <veeag0$786f$2@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
<lmvkisF860uU2@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Oct 2024 19:09:21 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="fb953ca9d31e98c34c2436e63d685284";
logging-data="237775"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18FvVjJqpqeQwG0+vrJY5XQTT971xIw8tQ="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:PtlxUfyNOVIwH1gP3mfon1/d6aY=
View all headers

Il Sat, 12 Oct 2024 17:57:16 +0200, Frank Winkler ha scritto:

> I think you're right. But why doesn't it work in ksh?

Uhm... It should work. Here it works, at least.

And sometimes something like that *may* work in bash, too, provided
we set:
$ shopt -s lastpipe

But my command doesn't work instead, in bash. That's why:

| lastpipe
| If set, and job control is not active, the shell runs the last command
| of a pipeline not executed in the background in the current shell
| environment.
--
Bye, Lem

Subject: Re: Different variable assignments
From: Lawrence D'Oliv
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 21:32 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 21:32:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <veepth$ao2d$2@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
<lmvkisF860uU2@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Oct 2024 23:32:34 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c5355a95aaf967e5c35c649cc5a0b328";
logging-data="352333"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/zJlvU4UVV4Xg/XLXg9i5h"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:WkL554QEIrPl6KyDEAPBqHxpIyU=
View all headers

On Sat, 12 Oct 2024 17:57:16 +0200, Frank Winkler wrote:

> I'm still thinking about the difference between "< <(...)" and "<<<
> `...`"

Not sure about the extra “<”, but “<(«cmd»)” gets substituted with the
name of a file (i.e. not stdin) that the process can open and read to get
the output of «cmd». Similarly “>(«cmd»)” gets substituted with the name
of a file (i.e. not stdout) that the process can open and write to feed
input to waiting «cmd».

“<<” and “<<<”, on the other hand, are for specifying alternative sources
of inline data for stdin, or you can use “«fd»<<” and “«fd»<<<” to specify
an alternative «fd» that the process will expect to find already open for
reading, to obtain that data.

Subject: Re: Different variable assignments
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 21:47 UTC
References: 1 2 3 4 5 6 7 8 9
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: Different variable assignments
Date: Sat, 12 Oct 2024 23:47:34 +0200
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <veeqpn$au42$1@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
<lmvkisF860uU2@mid.individual.net> <veepth$ao2d$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Oct 2024 23:47:36 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2cdacf41ca5404b51bb3ae13b0955324";
logging-data="358530"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/SN5pol3eWw5gXge5wFRya"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:TahkJRQcQim6cPvrcFfVWTaWYao=
In-Reply-To: <veepth$ao2d$2@dont-email.me>
X-Enigmail-Draft-Status: N1110
View all headers

On 12.10.2024 23:32, Lawrence D'Oliveiro wrote:
> On Sat, 12 Oct 2024 17:57:16 +0200, Frank Winkler wrote:
>
>> I'm still thinking about the difference between "< <(...)" and "<<<
>> `...`"
>
> Not sure about the extra “<”,

'<(...)' executes the command indicated by '...' and provides a file
descriptor, something like '/dev/fd/5', which (being effectively a
filename) can be redirected to the 'read' command.

The shell's 'read' command doesn't read from files but from stdin,
so if 'read's input is in a file or is the output of a command (as in
this case) you have to do a redirection; for the first case
read < file
and in case of a process substitution (a file named like /dev/fd/5)
read < <(some command)
which sort of "expands" to something like
read < /dev/fd/5

So it's no "extra" '<', it's just a necessary redirection for a
command that reads from 'stdin' but not from files.

Janis

> but “<(«cmd»)” gets substituted with the
> name of a file (i.e. not stdin) that the process can open and read to get
> the output of «cmd». Similarly “>(«cmd»)” gets substituted with the name
> of a file (i.e. not stdout) that the process can open and write to feed
> input to waiting «cmd».
>
> [...]

Subject: Re: Different variable assignments
From: Lawrence D'Oliv
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 21:50 UTC
References: 1 2 3 4 5 6 7 8 9 10
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 21:50:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <veeqvd$ao2d$10@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
<lmvkisF860uU2@mid.individual.net> <veepth$ao2d$2@dont-email.me>
<veeqpn$au42$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Oct 2024 23:50:37 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="c5355a95aaf967e5c35c649cc5a0b328";
logging-data="352333"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/X5XPIL6OAzPZVUK08QepJ"
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:QdXrxLCTboae/ah6OP+LX1ZWPZ0=
View all headers

On Sat, 12 Oct 2024 23:47:34 +0200, Janis Papanagnou wrote:

> '<(...)' executes the command indicated by '...' and provides a file
> descriptor, something like '/dev/fd/5', which (being effectively a
> filename) can be redirected to the 'read' command.

It’s an actual file name. The process treats it as just another filename
argument. The fact that it encodes a file descriptor is something OS-
specific, that only code that wants to create such names (like the shell)
has to worry about.

> The shell's 'read' command doesn't read from files but from stdin

It can read from any file currently open for reading.

> So it's no "extra" '<' ...

Ah, I see. Instead of “< <(«cmd›)”, you could have just written
“0<(«cmd»)”.

Subject: Re: Different variable assignments
From: Janis Papanagnou
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 21:56 UTC
References: 1 2 3 4 5 6 7 8 9 10 11
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: Different variable assignments
Date: Sat, 12 Oct 2024 23:56:33 +0200
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <veeraj$b0e5$1@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
<lmvkisF860uU2@mid.individual.net> <veepth$ao2d$2@dont-email.me>
<veeqpn$au42$1@dont-email.me> <veeqvd$ao2d$10@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 12 Oct 2024 23:56:35 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="2cdacf41ca5404b51bb3ae13b0955324";
logging-data="360901"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19npg4vVe0A58p4lyklctqw"
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101
Thunderbird/45.8.0
Cancel-Lock: sha1:25sIRmck3keXXK+tLQcuHDa2QfA=
In-Reply-To: <veeqvd$ao2d$10@dont-email.me>
View all headers

On 12.10.2024 23:50, Lawrence D'Oliveiro wrote:
> On Sat, 12 Oct 2024 23:47:34 +0200, Janis Papanagnou wrote:
>
>> '<(...)' executes the command indicated by '...' and provides a file
>> descriptor, something like '/dev/fd/5', which (being effectively a
>> filename) can be redirected to the 'read' command.
>
> It’s an actual file name. The process treats it as just another filename
> argument.

Exactly. (That's what I was saying.) '/dev/fd/5' acts like a file/path
name (but only on systems that support /dev/fd mechanism).

> The fact that it encodes a file descriptor is something OS-
> specific, that only code that wants to create such names (like the shell)
> has to worry about.
>
>> The shell's 'read' command doesn't read from files but from stdin
>
> It can read from any file currently open for reading.
>
>> So it's no "extra" '<' ...
>
> Ah, I see. Instead of “< <(«cmd›)”, you could have just written
> “0<(«cmd»)”.

No.

(1388)$ read <(cat hello_world)
ksh: read: /dev/fd/3: invalid variable name
(1389)$ read < <(cat hello_world)
(1390)$ echo $REPLY
Hello world!
(1391)$ read 0<(cat hello_world)
ksh: read: /dev/fd/3: invalid variable name

Janis

Subject: Re: Different variable assignments
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 23:07 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 23:07:41 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <veevft$aqpc$1@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
<lmvkisF860uU2@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 13 Oct 2024 01:07:41 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="42a66be9b83a86cad0effc1bfd61b3e1";
logging-data="355116"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18J4BtBnnu5X/2SroIiOH8QWLfd9MrpDqE="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:shbmU4YFfO7l/AiMqKl4bOEMLJM=
View all headers

Il Sat, 12 Oct 2024 17:57:16 +0200, Frank Winkler ha scritto:

> I'm still thinking about the difference between "< <(...)" and "<<<`...`"

As already pointed out by Lawrence:

1) "command2 <<<`command1`": `command2`, equal to the preferable[*]
$(command2), can be seen as the output of command2: a string. So with
<<< you are telling the shell to take this string as input on the
standard input of command2. So: execute command1, then take its output
as the input of command2. This is called *command* substitution:
substitution of a command with its output.

[*] No characters are special between parenthesis: easier.

2) "command2 < <(process_of_command1)": here process, which is the
"active running instance" of command1 - enough: remove the difference,
think of command1 and stop - is run with its output connected to a
named FIFO pipe file (or to some file in /dev/fd).
So <(process_of_command1) is expanded as the name of this file.
The first < is simple input redirection.
So: execute command1, connect the output of its process to a special
file, redirect this special file to input of command2.
This is called *process* output substitution: substitute a
process with the name of its output file.
Process substitution does work only on systems supporting named pipes
or /dev/fd/... so it's less universal than command substitution.

Some practical differences. For example, try:

$ cat <<<$(while true; do echo yes; done)

Nothing: cat is waiting for the other stuff to end. But it won't end,
in this case! Gawsh!

$ cat < <( while true; do echo yes; done)

Rock'n'roll!

> And I would be happy with this one if there was a notation "the other
> way round" ... something like "... >>> $var"

You're more the straightforward type of guy, eh! That's fine! ;)
But, sorry, '>>>' is still to come. In bash, at least. :-)
--
Bye, Lem

Subject: Re: Different variable assignments
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 23:10 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 23:10:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <veevke$aqpc$2@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
<lmvkisF860uU2@mid.individual.net> <veevft$aqpc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 13 Oct 2024 01:10:06 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="42a66be9b83a86cad0effc1bfd61b3e1";
logging-data="355116"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PLeJquYGRLPvHgyThQMCAj3ww+Q0ceQ0="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:ectkUYpvplE1ny7P7mOjK7yDC90=
View all headers

Il Sat, 12 Oct 2024 23:07:41 -0000 (UTC), Lem Novantotto ha scritto:

> 1) "command2 <<<`command1`": `command2`, equal to the preferable[*]
> $(command2),

Sorry:

1) "command2 <<<`command1`": `command1`, equal to the preferable[*]
$(command1)
--
Bye, Lem

Subject: Re: Different variable assignments
From: Lem Novantotto
Newsgroups: comp.unix.shell
Organization: A noiseless patient Spider
Date: Sat, 12 Oct 2024 23:39 UTC
References: 1 2 3 4 5 6 7 8 9
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Lem@none.invalid (Lem Novantotto)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Sat, 12 Oct 2024 23:39:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <vef1bb$brsm$1@dont-email.me>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
<lmvkisF860uU2@mid.individual.net> <veevft$aqpc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 13 Oct 2024 01:39:23 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="42a66be9b83a86cad0effc1bfd61b3e1";
logging-data="389014"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Vk6r+JtAhPvROMViLHLUS0AmMZrrhhzY="
User-Agent: Pan/0.160 (Toresk; )
Cancel-Lock: sha1:FuqarLGe4NuDFJsZTHNnX2MLag8=
View all headers

Il Sat, 12 Oct 2024 23:07:41 -0000 (UTC), Lem Novantotto ha scritto:

> As already pointed out by Lawrence:

And by Janis, of course!
I apologize.
--
Bye, Lem

Subject: Re: Different variable assignments
From: Frank Winkler
Newsgroups: comp.unix.shell
Date: Tue, 15 Oct 2024 11:46 UTC
References: 1 2 3 4 5 6 7 8
Path: eternal-september.org!news.eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: usenet@f.winkler-ka.de (Frank Winkler)
Newsgroups: comp.unix.shell
Subject: Re: Different variable assignments
Date: Tue, 15 Oct 2024 13:46:42 +0200
Lines: 31
Message-ID: <ln7313Fc93dU1@mid.individual.net>
References: <lmt83dFsvbvU3@mid.individual.net>
<lmt90sFr1idU1@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net>
<vecl6n$d0r$1@dont-email.me> <lmuniuF632tU1@mid.individual.net>
<vedlc2$4vi6$1@dont-email.me> <vedofj$5g3v$1@dont-email.me>
<lmvkisF860uU2@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net ZPQYovjhPKV8C966coq5wAo5LpOen0558rcoHelBN+w1bA4zDa
Cancel-Lock: sha1:DMRyUObRDIN/5y0aWBbxgaqIDGM= sha256:lbQUPH7TBh1x+xNA1kN9Byjun/RBVUM5UaA7MBgBppw=
User-Agent: Mozilla Thunderbird Beta
Content-Language: en-US
In-Reply-To: <lmvkisF860uU2@mid.individual.net>
View all headers

On 12.10.2024 17:57, I wrote:

>I think you're right. But why doesn't it work in ksh?

BTW: in an interactive ksh, the example does work:

$ input=$(tty) && echo 123456789 | tee $input | grep -o 456 | tee $input
| read myvar && echo "myvar is $myvar"; input= ; myvar=
123456789
456
myvar is 456
$

And it also does when I put this into a ksh script.

The thing in question does

tty=`tty`
sudo openconnect -b ... |\
tee $tty | grep "^Session authentication will expire at" |\
cut -d ' ' -f 7- | read end

and this completely fails. Terminal output is missing, $end is empty and
the whole command doesn't seem to work. Without the last two lines, it's
working perfectly.
"sudo" also doesn't seem to be the problem as simple tests are working.

Regards

fw

Subject: Re: Different variable assignments
From: Kenny McCormack
Newsgroups: comp.unix.shell
Organization: The official candy of the new Millennium
Date: Sat, 19 Oct 2024 10:45 UTC
References: 1 2 3 4
Path: eternal-september.org!news.eternal-september.org!feeder3.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: Different variable assignments
Date: Sat, 19 Oct 2024 10:45:43 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <vf02kn$3dfm8$1@news.xmission.com>
References: <lmt83dFsvbvU3@mid.individual.net> <lmta1jFsvc0U1@mid.individual.net> <vecl6n$d0r$1@dont-email.me> <vecmp3$pur$1@dont-email.me>
Injection-Date: Sat, 19 Oct 2024 10:45:43 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="3587784"; 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 <vecmp3$pur$1@dont-email.me>,
Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
>On Sat, 12 Oct 2024 03:59:49 +0200, Janis Papanagnou wrote:
>
>> ... use bash-specifics like 'coproc' ...
>
>It isn't bash-specific.

People on these newsgroups often use phrases like "bash specific" as
synonyms for "Not strictly POSIX" (*), even though the bash feature under
discussion is also found in other shells. In fact, many bash-isms,
including "coproc", came originally from ksh. I'm sure Janis knows this.

--
The key difference between faith and science is that in science, evidence that
doesn't fit the theory tends to weaken the theory (that is, make it less likely to
be believed), whereas in faith, contrary evidence just makes faith stronger (on
the assumption that Satan is testing you - trying to make you abandon your faith).

Pages:123

rocksolid light 0.9.8
clearnet tor