Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <vecl6n$d0r$1@dont-email.me>
Deutsch   English   Français   Italiano  
<vecl6n$d0r$1@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Janis Papanagnou <janis_papanagnou+ng@hotmail.com>
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
Bytes: 2600

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