From: Lionel Thiry Date: 2004-10-15T07:35:30+09:00 Subject: Re: [nuby] shell-like substitution in a string Ara.T.Howard@noaa.gov a �crit : > On Thu, 14 Oct 2004, Lionel Thiry wrote: > >> Hi! >> >> I'd like to make some kind of substitution like in a shell, i.e. having: >> "${tool} -o ${target} -L${libpath} -l${lib} ${source}" >> >> with an env like this: >> env = { >> "tool" => "gcc", >> "target" => "hello.exe", >> "libpath" => "/usr/lib", >> "lib" => "somelib", >> "source" => "hello.c" >> } >> >> it should give: >> "gcc -o hello.exe -L/usr/lib -lsomelib hello.c" >> >> >> It is easy until I want to manage caracter escapement like >> "${var\\}weird}" which should give env["var}weird"], "\\${var}" which >> should give the simple string "${var}" and "\\\\${var}" which should be >> equivalent to "\\" + env["var"]. > > > i don't think you need to worry about that since 'var}weird' is not a valid > shell identifier - at least i can't seem to create a var by that name in > the > shell... Pertinent remark, noted. > >> Any idea of how I could manage that? > > > you can get bash's exact parameter expansion like this: > > jib:~ > cat a.rb > require 'session' I'm working on win2k with on-click installer ruby v1.8.1-13 and unfortunately, there is no session file that can be required. Lionel Thiry