Deutsch English Français Italiano |
<vbv8kd$blsb$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Harald Oehlmann <wortkarg3@yahoo.com> Newsgroups: comp.lang.tcl Subject: Re: Why do we need "eval"? (Expect question) Date: Thu, 12 Sep 2024 19:33:01 +0200 Organization: A noiseless patient Spider Lines: 48 Message-ID: <vbv8kd$blsb$1@dont-email.me> References: <vbv03t$1t4qm$1@news.xmission.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Thu, 12 Sep 2024 19:33:04 +0200 (CEST) Injection-Info: dont-email.me; posting-host="ae3a192b59388df87300ca25b56dbdf0"; logging-data="382859"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196iqgj8Gr6VNEFCQ05jRjb" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:JRBOslHVW6oXRGjZMk6gAM6Jjwk= In-Reply-To: <vbv03t$1t4qm$1@news.xmission.com> Content-Language: en-GB Bytes: 2357 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" ? > Kenny, thanks for the question. Here is the answer by a TCL'er without expect knowledge. "eval" does an additional round of substitutions. This happens for all elements and is intended, if a whole command is included in a variable. 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 Harald