From: Dominik Honnef Date: 2009-03-04T00:09:00+09:00 Subject: Re: expanding environment variable --R+My9LyyhiUvIEro Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On [Tue, 03.03.2009 23:58], Daniel Schoch wrote: > Dominik Honnef wrote: > > On [Tue, 03.03.2009 23:28], Daniel Schoch wrote: > >> Hi, > >>=20 > >> I have a string > >> s =3D "$DIR/test/$FILE" > >>=20 > >> Is there an easy way to expand this with the defined environment > >> variables? > > What do you mean by environment variables? The stuff in ENV, or the > > constants like __FILE__ or simply global variables? >=20 > I mean the stuff in ENV. > SHELL: > export DIR=3Dx > export FILE=3Dy.z >=20 > RUBY: > I'd like to know the easiest way from > s =3D "$DIR/test/$FILE" > to > s =3D "x/test/y.z" >=20 >=20 | >>> DIR=3Dx FILE=3Dy.z irb | >> s =3D "$DIR/test/$FILE".gsub(/\$\w+/) {|m| ENV[m[1..-1]]} | =3D> "x/test/y.z" Thats how I would do it. --=20 Dominik Honnef dominikho@gmx.net --R+My9LyyhiUvIEro Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkmtSFgACgkQePZ2jI1LDtevOACfZl7N0VrEij2SJDmC1eql0Bj1 vZIAnj9im3Vh+NW6LAG/C5MKjGSWgcFw =PR36 -----END PGP SIGNATURE----- --R+My9LyyhiUvIEro--