From owner-freebsd-questions@freebsd.org Wed Aug 9 11:16:00 2017 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 681A9DCA167 for ; Wed, 9 Aug 2017 11:16:00 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from bede.home.qeng-ho.org (bede.qeng-ho.org [217.155.128.241]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "fileserver.home.qeng-ho.org", Issuer "fileserver.home.qeng-ho.org" (not verified)) by mx1.freebsd.org (Postfix) with ESMTPS id 0B85F6D9C6 for ; Wed, 9 Aug 2017 11:15:59 +0000 (UTC) (envelope-from freebsd@qeng-ho.org) Received: from arthur.home.qeng-ho.org (arthur.home.qeng-ho.org [172.23.1.2]) by bede.home.qeng-ho.org (8.15.2/8.15.2) with ESMTP id v79AoO0q055765; Wed, 9 Aug 2017 11:50:24 +0100 (BST) (envelope-from freebsd@qeng-ho.org) Subject: Re: Is multi-line assignment to eval possible ? To: Manish Jain , "freebsd-questions@freebsd.org" References: From: Arthur Chance Message-ID: Date: Wed, 9 Aug 2017 11:50:24 +0100 User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 8bit X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 09 Aug 2017 11:16:00 -0000 On 08/08/2017 16:48, Manish Jain wrote: > > Hi, > > On my FreeBSD box, I was trying do something in a Bourne script which at > first seemed fairly trivial - but has now clouded my mind thoroughly. > > a=A > b=B > > eval ${a}_${b}="something" In this case you might want to check out the setvar builtin in /bin/sh: setvar variable value Assigns the specified value to the specified variable. The setvar command is intended to be used in functions that assign values to variables whose names are passed as parameters. In general it is better to write “variable=value” rather than using setvar. so that eval could be written as setvar ${a}_${b} "something" > No problems so far. I get a new variable A_B that stores "something" > > But if I spread the assignment over 2 lines as under : > > eval ${a}_${b}="some > thing" > > The shell barks at me that it could find no command called 'thing'. Is > there some hack that I could use to get eval to 'understand' that the > assignment has an embedded newline ? Yes, but using setvar avoids the need: setvar ${a}_${b} "some thing" works OK. -- An amusing coincidence: log2(58) = 5.858 (to 0.0003% accuracy).