Sujet : Re: Different variable assignments
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.unix.shellDate : 24. Oct 2024, 12:21:27
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vfdajn$3k665$1@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
lnuidqFk4dU1@mid.individual.net>,
Frank Winkler <
usenet@f.winkler-ka.de> wrote:
On 15.10.2024 13:46, I wrote:
>
>The thing in question does
>
>tty=`tty`
>sudo openconnect -b ... |\
> tee $tty | grep "^Session authentication will expire at" |\
> cut -d ' ' -f 7- | read end
>
>and this completely fails. Terminal output is missing, $end is empty and
>the whole command doesn't seem to work. Without the last two lines, it's
>working perfectly.
>"sudo" also doesn't seem to be the problem as simple tests are working.
>
OK, let's try to normalize this. But first, please tell which shell you
are targeting. I.e., how much old-compatibility do you need?
I'm going to assume bash, but there isn't much difference. In particular,
note that $() is POSIX, so you really don't need to ever mess with ``.
Also note: You do not need \ at the end of the line if the line ends with |
(also true for lines that end with || or && - and possibly others)
Anyway, this should do it:
tty=$(tty)
end="$(sudo openconnect -b ... |
tee $tty | grep "^Session authentication will expire at" |
cut -d ' ' -f 7-)"
Note also that the grep and the cut could be merged into a single
invocation of awk - but I don't know enough about what you're doing to be
more specific. You can probably also eliminate all of the "tty" stuff by
writing either to /dev/tty (which is generic Unix) or /dev/stderr (which
might be Linux-specific). Also, if you use gawk (GNU awk), then you can
write to /dev/stderr from within AWK and eliminate all of the "tee" stuff
as well.
-- "Remember when teachers, public employees, Planned Parenthood, NPR and PBScrashed the stock market, wiped out half of our 401Ks, took trillions inTARP money, spilled oil in the Gulf of Mexico, gave themselves billions inbonuses, and paid no taxes? Yeah, me neither."