Project

General

Profile

This project is closed and read-only.

Actions

Bug #3321

closed

Kernel#system do not execute command in subshell even if it contains variable assignments

Bug #3321: Kernel#system do not execute command in subshell even if it contains variable assignments

Added by dram (Xin Wang) over 16 years ago. Updated over 15 years ago.

Status:
Rejected
Assignee:
-
[ruby-core:30320]

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


Related issues 1 (0 open1 closed)

Has duplicate Ruby - Feature #3426: exec doesn't allow command lines which begin with an env variable assignmentRejectedmame (Yusuke Endoh)Actions

Updated by mame (Yusuke Endoh) over 16 years ago Actions #1

  • 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
=end

Actions

Also available in: PDF Atom