Gentoo Archives: gentoo-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-dev@l.g.o
Subject: Re: [gentoo-dev] Re: evar_push/pop helpers
Date: Mon, 17 Jun 2013 16:06:40
Message-Id: 201306171206.35913.vapier@gentoo.org
In Reply to: Re: [gentoo-dev] Re: evar_push/pop helpers by Mike Frysinger
1 On Monday 17 June 2013 01:42:15 Mike Frysinger wrote:
2 > On Sunday 02 June 2013 13:38:04 Steven J. Long wrote:
3 > > On Sat, Jun 01, 2013 at 11:03:20PM -0400, Mike Frysinger wrote:
4 > > > +# is not specified, the var will be unset.
5 > > > +evar_push_set() {
6 > > > + local var=$1
7 > > > + evar_push ${var}
8 > > > + case $# in
9 > > > + 1) unset ${var} ;;
10 > > > + 2) eval ${var}=\$2 ;;
11 > >
12 > > I wish you wouldn't use eval for this. I know it's technically okay here,
13 > > or would be if you verified the parameter, but bash has printf -v for
14 > > this purpose:
15 >
16 > interesting, i hadn't seen that before ... looks new to bash-3.1. /me
17 > tucks that into his tool belt.
18 >
19 > although it doesn't quite work in the edge case where the value is an empty
20 > string. consider:
21 > unset x
22 > printf -v x ''
23 > echo ${x+set}
24 >
25 > that should show "set", but it does not. i'll have to keep `eval ${var}=`
26 > when the value we're setting is empty. or just keep the eval code since i
27 > have to do eval anyways at that point.
28 >
29 > i'll report it upstream to the bash guys.
30
31 looks like it can be worked around by doing:
32 printf -v x '%s' ''
33 which is arguably what we want anyways
34 -mike

Attachments

File name MIME type
signature.asc application/pgp-signature