Deutsch English Français Italiano |
<lmuniuF632tU1@mid.individual.net> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Frank Winkler <usenet@f.winkler-ka.de> 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> Bytes: 2772 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