Sujet : lastpipe (Was: Different variable assignments)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shellDate : 19. Oct 2024, 12:50:07
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vf06df$3dhev$3@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
vecl6n$d0r$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+
ng@hotmail.com> wrote:
...
(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.
Setting "lastpipe" works (sort of) in bash.
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.)
There are lots of workarounds, but I think the main takeaway is that the
obvious-but-wrong idiom of "cmd | read foo" is just TBA.
-- Life's big questions are big in the sense that they are momentous. However, contrary toappearances, they are not big in the sense of being unanswerable. It is only that the answersare generally unpalatable. There is no great mystery, but there is plenty of horror. (https://en.wikiquote.org/wiki/David_Benatar)