[nuby] shell-like substitution in a string

Lionel,

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"

    If there any problem with simply:

"#{env['tool']} -o #{env['target']} -L#{env['libpath']} -l#{env['lib']}
#{env['source']}"

    I hope this helps.

    - Warren Brown

Warren Brown a écrit :

Lionel,

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"

    If there any problem with simply:

"#{env['tool']} -o #{env['target']} -L#{env['libpath']} -l#{env['lib']}
#{env['source']}"

    I hope this helps.

    - Warren Brown

I want to manage those cases too:

Initial description:
"${tool} -o ${target} -L${libpath} -l${lib} ${source}"

Env:
env = {
"tool" => "gcc",
"target" => "hello.exe${ext}",
"ext" => ".exe",
"libpath" => "/usr/lib",
"lib" => "somelib",
"source" => "hello.o"
}

Interpolation:
"gcc -o hello.exe -L/usr/lib -lsomelib hello.c"

Or:
Initial description:
"${tool} -o ${target} -L${libpath} -l${lib} ${sources}"

Env:
env = {
"tool" => "gcc",
"target" => "hello.exe${ext}",
"ext" => ".exe",
"libpath" => ["/usr/lib", "/usr/local/lib"],
"lib" => ["somelib", "anotherlib"],
"sources" => ["hello.o", "display.o", "other.o"]
}

Interpolation:
"gcc -o hello.exe -L/usr/lib -L/usr/local/lib -lsomelib -lanotherlib hello.o display.o other.o"

Then, no, simple ruby string substitution cannot fit into my goals. But thanks for the remark.

Lionel Thiry