Date: Wed, 9 Aug 2017 11:50:24 +0100 From: Arthur Chance <freebsd@qeng-ho.org> To: Manish Jain <bourne.identity@hotmail.com>, "freebsd-questions@freebsd.org" <freebsd-questions@freebsd.org> Subject: Re: Is multi-line assignment to eval possible ? Message-ID: <bb70ab65-3dcb-029d-7d74-2d824c2d04d8@qeng-ho.org> In-Reply-To: <VI1PR02MB120024405E8AC219206B8F6CF68A0@VI1PR02MB1200.eurprd02.prod.outlook.com> References: <VI1PR02MB120024405E8AC219206B8F6CF68A0@VI1PR02MB1200.eurprd02.prod.outlook.com>
next in thread | previous in thread | raw e-mail | index | archive | help
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).
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bb70ab65-3dcb-029d-7d74-2d824c2d04d8>