Is multi-line assignment to eval possible ?

Arthur Chance freebsd at
Wed Aug 9 11:16:00 UTC 2017

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

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

works OK.

An amusing coincidence: log2(58) = 5.858 (to 0.0003% accuracy).

More information about the freebsd-questions mailing list