Re: Different variable assignments

Liste des GroupesRevenir à cu shell 
Sujet : Re: Different variable assignments
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shell
Date : 19. Oct 2024, 12:45:30
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vf064q$3dhev$1@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <vec3qb$3q4ms$3@dont-email.me>,
Lawrence D'Oliveiro  <ldo@nz.invalid> wrote:
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

I'm actually a fan of "coproc" in bash, and I use it in my scripting, but I
think it is overkill in most cases.  The most general command for variable
assignment (in bash) is "mapfile".  "mapfile" supercedes "coproc" in most
cases.  For the possible benefit of OP, here's the standard idiom for using
"mapfile", using the "sw_vers" program, which OP mentioned in passing
(AFAIK, "sw_vers" is a Mac OS thing):

    mapfile -t < <(sw_vers)

which populates the array MAPFILE.

A couple of other points:
    1) When using "coproc", you can get away with just $COPROC for the
    output of the co-process.  This is a little easier to type than
    ${COPROC[0]} - even if this does get flagged as a warning by the
    "shellcheck" program.  Note that in bash, all variables are arrays;
    it's just that most only have one element:
% bash -c 'echo ${HOME[0]}'
/home/me
%

    2) OP's main concern actually seems to be aesthetic.  He just wants the
    variable name at the end of the line instead of at the beginning.  Kind
    of like the difference between the two styles of assembler languages,
    where some are: "move src,dst" and others (most) are "move dst,src".
    (It's been a long time since I've done assembler language.)

Finally, note that you just generally learn to avoid the (wrong) idiom of:

    cmd | read bar

because you learn early on that it doesn't work.  I think the most basic
(works in any sh-like shell, even in the bad old days of Solaris)
alternative is:

    read bar << EOF
    $(cmd)
    EOF


--
https://www.rollingstone.com/politics/politics-news/the-10-dumbest-things-ever-said-about-global-warming-200530/

RS contributor Bill McKibben lambasted this analysis in his 2007 book, Deep Economy.
It's nice to have microelectronics; it's necessary to have lunch,  wrote McKibben.

Date Sujet#  Auteur
11 Oct 24 * Different variable assignments60Frank Winkler
11 Oct 24 +* Re: Different variable assignments33John-Paul Stewart
11 Oct 24 i`* Re: Different variable assignments32Frank Winkler
12 Oct 24 i `* Re: Different variable assignments31Janis Papanagnou
12 Oct 24 i  +* Re: Different variable assignments5Lawrence D'Oliveiro
19 Oct 24 i  i`* Re: Different variable assignments4Kenny McCormack
19 Oct 24 i  i `* Re: Different variable assignments3Janis Papanagnou
19 Oct 24 i  i  `* coprocs in bash & ksh (Was: Different variable assignments)2Kenny McCormack
19 Oct 24 i  i   `- Re: coprocs in bash & ksh (Was: Different variable assignments)1Janis Papanagnou
12 Oct 24 i  +* Re: Different variable assignments24Frank Winkler
12 Oct 24 i  i+- Re: Different variable assignments1Lawrence D'Oliveiro
12 Oct 24 i  i`* Re: Different variable assignments22Janis Papanagnou
12 Oct 24 i  i +* Re: Different variable assignments20Lem Novantotto
12 Oct 24 i  i i`* Re: Different variable assignments19Frank Winkler
12 Oct 24 i  i i +* Re: Different variable assignments3Lem Novantotto
19 Oct 24 i  i i i`* lastpipe (Was: Different variable assignments)2Kenny McCormack
19 Oct 24 i  i i i `- Re: lastpipe (Was: Different variable assignments)1Lem Novantotto
12 Oct 24 i  i i +* Re: Different variable assignments4Lawrence D'Oliveiro
12 Oct 24 i  i i i`* Re: Different variable assignments3Janis Papanagnou
12 Oct 24 i  i i i `* Re: Different variable assignments2Lawrence D'Oliveiro
12 Oct 24 i  i i i  `- Re: Different variable assignments1Janis Papanagnou
13 Oct 24 i  i i +* Re: Different variable assignments3Lem Novantotto
13 Oct 24 i  i i i+- Re: Different variable assignments1Lem Novantotto
13 Oct 24 i  i i i`- Re: Different variable assignments1Lem Novantotto
15 Oct 24 i  i i `* Re: Different variable assignments8Frank Winkler
24 Oct 24 i  i i  `* Re: Different variable assignments7Frank Winkler
24 Oct 24 i  i i   +* Re: Different variable assignments3Kenny McCormack
24 Oct 24 i  i i   i`* Re: Different variable assignments2Frank Winkler
25 Oct 24 i  i i   i `- Re: Different variable assignments1Janis Papanagnou
25 Oct 24 i  i i   `* Re: Different variable assignments3Lem Novantotto
25 Oct 24 i  i i    `* tee with no args is a no-op (Was: Different variable assignments)2Kenny McCormack
25 Oct 24 i  i i     `- Re: tee with no args is a no-op (Was: Different variable assignments)1Lem Novantotto
12 Oct 24 i  i `- Re: Different variable assignments1Frank Winkler
19 Oct 24 i  `- lastpipe (Was: Different variable assignments)1Kenny McCormack
11 Oct 24 `* Re: Different variable assignments26Helmut Waitzmann
11 Oct 24  +* Re: Different variable assignments23Frank Winkler
11 Oct 24  i+* Re: Different variable assignments21Lawrence D'Oliveiro
19 Oct 24  ii`* Re: Different variable assignments20Kenny McCormack
19 Oct 24  ii `* Re: Different variable assignments19Janis Papanagnou
19 Oct 24  ii  +* coproc or whatever in bash and ksh (Was: Different variable assignments)4Kenny McCormack
19 Oct 24  ii  i`* Re: coproc or whatever in bash and ksh (Was: Different variable assignments)3Janis Papanagnou
19 Oct 24  ii  i +- Re: coproc or whatever in bash and ksh (Was: Different variable assignments)1Janis Papanagnou
19 Oct 24  ii  i `- Re: coproc or whatever in bash and ksh (Was: Different variable assignments)1Kenny McCormack
19 Oct 24  ii  `* Re: Different variable assignments14Lawrence D'Oliveiro
20 Oct 24  ii   `* Re: Different variable assignments13Kenny McCormack
20 Oct 24  ii    `* Re: Different variable assignments12Janis Papanagnou
20 Oct 24  ii     `* coprocs - again (Was: Different variable assignments)11Kenny McCormack
25 Oct 24  ii      `* Re: coprocs - again (Was: Different variable assignments)10Janis Papanagnou
25 Oct 24  ii       +* Re: coprocs - again (Was: Different variable assignments)8Lawrence D'Oliveiro
25 Oct 24  ii       i+* Re: coprocs - again (Was: Different variable assignments)6Janis Papanagnou
25 Oct 24  ii       ii`* Subjective "valuations" are all we have (Was: coprocs - again (Was: Different variable assignments))5Kenny McCormack
25 Oct 24  ii       ii `* Re: Subjective "valuations" are all we have (Was: coprocs - again (Was: Different variable assignments))4Janis Papanagnou
25 Oct 24  ii       ii  +- Re: Subjective "valuations" are all we have (Was: coprocs - again (Was: Different variable assignments))1Lem Novantotto
25 Oct 24  ii       ii  `* Re: Subjective "valuations" are all we have (Was: coprocs - again (Was: Different variable assignments))2Kenny McCormack
26 Oct 24  ii       ii   `- Re: Subjective "valuations" are all we have (Was: coprocs - again (Was: Different variable assignments))1Janis Papanagnou
25 Oct 24  ii       i`- Re: coprocs - again (Was: Different variable assignments)1Kenny McCormack
25 Oct 24  ii       `- How to do multiple concurrent coprocs in ksh (Was: coprocs - again (Was: Different variable assignments))1Kenny McCormack
12 Oct 24  i`- Re: Different variable assignments1Christian Weisgerber
15 Nov 24  `* Re: Different variable assignments2Kenny McCormack
16 Nov 24   `- Re: Different variable assignments1Lem Novantotto

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal