This project is closed and read-only.
Bug #3321
closedKernel#system do not execute command in subshell even if it contains variable assignments
Description
=begin
When there are variable assignments in command, Kernel#system in Ruby v1.9 execute it using bare fork&exec instead subshell. It cause command execution failed silently.
So '=' must also be a special character to be recognized as a sign to execute command in subshell.
For example:
$ cat ./script.sh
#!/bin/sh
echo $TEST
$ irb
irb(main):001:0> system('TEST=test ./script.sh')
=> nil
irb(main):002:0> system('TEST=test ./script.sh 2>/dev/null')
test
=> true
irb(main):003:0> ~
=end
Updated by mame (Yusuke Endoh) over 16 years ago
- Status changed from Open to Rejected
=begin
Hi,
So '=' must also be a special character to be recognized as a sign to execute command in subshell.
It may cause compatibility issue.
$ cat scr=ipt
#!/bin/sh
echo arg:$*
echo scr:$scr
$ PATH=. ./ruby -e 'system("scr=ipt ./scr=ipt")'
arg:./scr=ipt
scr:
$ PATH=. ./ruby -e 'system("scr=ipt ./scr=ipt 2> /dev/null")'
arg:
scr:ipt
Yes, I admit it is a pedantic example. But process invocation may
cause singinicant result (such as breaking system), so we cannot be
too conservative, I think.
For your purpose, I recommend you use env option
system({"TEST" => "test"}, "./script.sh")
If you really want to execute it via shell, you can use ';'
system("TEST=test ./scr=ipt;")'
Thanks,
--
Yusuke Endoh mame@tsg.ne.jp
=end