Sujet : Re: Why do we need "eval"? (Expect question)
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.lang.tclDate : 12. Sep 2024, 19:45:30
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <vbvcsa$1tb4p$1@news.xmission.com>
References : 1 2
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <
vbv8kd$blsb$1@dont-email.me>,
Harald Oehlmann <
wortkarg3@yahoo.com> wrote:
Am 12.09.2024 um 17:07 schrieb Kenny McCormack:
Consider this (Unix/Linux/bash) command line:
$ expect -- /dev/fd/3 3<<< 'eval spawn -noecho printf {{\t%s\n}}
$argv;interact' $(seq 1 10)
This correctly generates the output (each line starts with a tab):
1
2
3
4
5
6
7
8
9
10
But notice how we have to use "eval" in order to split up the args in $argv.
And, since we are using "eval", we have to "double quote" (with {}) the
"format" arg to "printf". It'd be nice if neither of these things were
necessary.
I've always believed that "eval" was "evil" and to be avoided if at all
possible - both in shell and in Tcl. It has strange side effects, such as
we see here (the need to "double quote"). Is there any way to get the
above effect w/o using "eval" ?
...
To only expand some arguments, the list expansion operator may be used:
>
In your case:
eval spawn -noecho printf {{\t%s\n}} $argv
equal to:
spawn -noecho printf {\t%s\n} {*}$argv
eventually, this works to:
spawn -noecho printf \t%s\n {*}$argv
Indeed it does. Thanks! This solves my issue.
ISTM that this {*} thing is a relatively recent addition to the langauge,
since Expect has been around for a long time, and most of the scripts that
do this sort of thing were written long ago.
-- person woman man camera tv