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" ?
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
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.
spawn -noecho printf {\t%s\n} {*}$argv
eventually, this works to:
spawn -noecho printf \t%s\n {*}$argv
Kenny McCormack <[email protected]> wrote:
ISTM that this {*} thing is a relatively recent addition to the langauge,
Not really, it was added in 8.5, which was released Feb 12, 2016 [1]. Although 2016 *is* relatively recent in regards to many expect scripts.
since Expect has been around for a long time, and most of the scripts that >> do this sort of thing were written long ago.
Before 8.5, 'eval' was the way to perform the "splicing" that {*}
provides.
[1] https://www.tcl.tk/software/tcltk/8.5.tml
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.
ISTM that this {*} thing is a relatively recent addition to the langauge,
Not really, it was added in 8.5, which was released Feb 12, 2016 [1]. >Although 2016 *is* relatively recent in regards to many expect scripts.
since Expect has been around for a long time, and most of the scripts that >> do this sort of thing were written long ago.
Before 8.5, 'eval' was the way to perform the "splicing" that {*}
provides.
spawn -noecho printf {\t%s\n} {*}$argv
eventually, this works to:
spawn -noecho printf \t%s\n {*}$argv
Do note that the second one causes \t and \n to be interpreted by Tcl's >parser, so printf gets passed a literal tab and literal newline in its >parameter list. The first passes the \ and t characters on to printf,
and then printf does the interpretation.
Both likely work fine for printf, but may not work fine for all
possible external commands.
In article <vc0lm1$npv9$[email protected]>,
Harald Oehlmann <[email protected]> wrote:
Am 12.09.2024 um 20:45 schrieb Kenny McCormack:
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.
"Relatively recent" is quite relative. Here is the relevant changes file >>entry:
2006-11-02 (feature change)[TIP 293] Replace {expand} with {*} (hobbs)
*** POTENTIAL INCOMPATIBILITY with previous 8.5 alphas only ***
;-)
The other poster seemed to think 2016 (not 2006). That's still 8 years ago...
Am 12.09.2024 um 20:45 schrieb Kenny McCormack:
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.
"Relatively recent" is quite relative. Here is the relevant changes file >entry:
2006-11-02 (feature change)[TIP 293] Replace {expand} with {*} (hobbs)
*** POTENTIAL INCOMPATIBILITY with previous 8.5 alphas only ***
;-)
| Sysop: | Keyop |
|---|---|
| Location: | Huddersfield, West Yorkshire, UK |
| Users: | 715 |
| Nodes: | 16 (0 / 16) |
| Uptime: | 168:21:09 |
| Calls: | 12,096 |
| Calls today: | 4 |
| Files: | 15,003 |
| Messages: | 6,517,822 |