From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10596 invoked from network); 14 Mar 2006 09:04:12 -0000 X-Spam-Checker-Version: SpamAssassin 3.1.0 (2005-09-13) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=AWL,BAYES_00, FORGED_RCVD_HELO autolearn=ham version=3.1.0 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 14 Mar 2006 09:04:12 -0000 Received: (qmail 42721 invoked from network); 14 Mar 2006 09:04:05 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 14 Mar 2006 09:04:05 -0000 Received: (qmail 9879 invoked by alias); 14 Mar 2006 09:03:57 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 10014 Received: (qmail 9869 invoked from network); 14 Mar 2006 09:03:56 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 14 Mar 2006 09:03:56 -0000 Received: (qmail 41590 invoked from network); 14 Mar 2006 09:03:56 -0000 Received: from david.siemens.de (192.35.17.14) by a.mx.sunsite.dk with SMTP; 14 Mar 2006 09:03:54 -0000 Received: from mail2.siemens.de (localhost [127.0.0.1]) by david.siemens.de (8.12.6/8.12.6) with ESMTP id k2E93rEr031683 for ; Tue, 14 Mar 2006 10:03:53 +0100 Received: from mchp771a.ww002.siemens.net (mchp771a.ww002.siemens.net [139.25.131.189]) by mail2.siemens.de (8.12.6/8.12.6) with ESMTP id k2E93qOD017575 for ; Tue, 14 Mar 2006 10:03:53 +0100 Received: from MCHP7R6A.ww002.siemens.net ([139.25.131.164]) by mchp771a.ww002.siemens.net with Microsoft SMTPSVC(6.0.3790.1830); Tue, 14 Mar 2006 10:03:52 +0100 X-MimeOLE: Produced By Microsoft Exchange V6.5 Content-class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable Subject: Can I do without "eval" here? Date: Tue, 14 Mar 2006 10:03:51 +0100 Message-ID: <6F0CB04509C11D46A54232E852E390AC01004881@MCHP7R6A.ww002.siemens.net> X-MS-Has-Attach: X-MS-TNEF-Correlator: Thread-Topic: Can I do without "eval" here? Thread-Index: AcZHRja08lXTdb20RjyfSSeSljOBQQ== From: "Com MN PG P E B Consultant 3" To: "zsh-users Mailinglist" X-OriginalArrivalTime: 14 Mar 2006 09:03:52.0994 (UTC) FILETIME=[376EF820:01C64746] Maybe just a matter of style, but here is a (simplified) version of a problem which I have solved, but where I am not satisfied with the solution ... Assume I have a command CMD which can be called in the following ways: CMD -x FILENAME CMD -y 'this is some string with alphanumerics and spaces' FILENAME I call this CMD from a skript MYSCRIPT. If the skript is called with 1 parameter, I use the second form and put the parameter into the argument of my -y option. If MYSCRIPT is called without parameters, I use the -x option. For sake of simplicity, we can assume that the FILENAME is always hardcoded. That is, if someone calls MYSCRIPT without any arguments, i.e. MYSCRIPT it should execute CMD -x foo But if MYSCRIPT is called like this: MYSCRIPT "bar baz" it should execute=20 CMD -y 'bar baz' foo Here is my solution (which I ask you to improve): #!/bin/zsh if [[ $# -eq 0 ]] then options=3D-x else options=3D"-y '$1'" fi eval CMD $options foo The 'eval' is necessary here, because if I write just CMD $options foo CMD would see for example -y 'bar baz' as first argument, and not just -y. What I don't like in this example, is the usage of eval. Although it is harmless in this particular case, the filename 'foo', which is hardcoded here, comes in as a parameter too in my real application, and=20 this means that it undergoes one level of evaluation too, which would yield wrong results when it contains, say, a $ character.=20 Of course one might argued that when you are thinking of filenames with $, you are doomed anyway, but=20 still I'm not a big fan of using 'eval' anyway, so I wonder whether this can be done without eval too.... Ronald