Liste des Groupes | Revenir à cu shell |
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
Les messages affichés proviennent d'usenet.