From: Yusuke Endoh Date: 2010-04-10T11:34:01+09:00 Subject: [ruby-core:29403] [Bug #1573] $0 behaves unexpectedly Issue #1573 has been updated by Yusuke Endoh. Assigned to set to Nobuyoshi Nakada Hi, > consider two files, foo.rb and bar.rb, both simply contain: "p $0". i run "ruby -rbar.rb foo.rb". > > using 1.8.6 and the same setup, the output is: > > "foo.rb" > "foo.rb" > > using 1.9.1p0 the output is: > > "ruby" > "foo.rb" I think this is not an intended change. In fact, nobu fixed this at r23812 (accidentally?) once. But the symptom reoccers at r25330 for fixing another bug. Nobu, how about the following patch? diff --git a/ruby.c b/ruby.c index 5c1eef0..489942d 100644 --- a/ruby.c +++ b/ruby.c @@ -1353,6 +1353,8 @@ process_options(int argc, char **argv, struct cmdline_options *opt) } } ruby_init_gems(!(opt->disable & DISABLE_BIT(gems))); + rb_progname = opt->script_name; + rb_vm_set_progname(rb_progname); ruby_set_argv(argc, argv); process_sflag(&opt->sflag); @@ -1397,8 +1399,6 @@ process_options(int argc, char **argv, struct cmdline_options *opt) tree = load_file(parser, opt->script, 1, opt); }); } - rb_progname = opt->script_name; - rb_vm_set_progname(rb_progname); if (opt->dump & DUMP_BIT(yydebug)) return Qtrue; if (opt->ext.enc.index >= 0) { @@ -1590,7 +1590,12 @@ load_file_internal(VALUE arg) else if (!NIL_P(c)) { rb_io_ungetbyte(f, c); } - require_libraries(&opt->req_list); /* Why here? unnatural */ + { + VALUE progname = rb_progname; + rb_progname = Qnil; + require_libraries(&opt->req_list); /* Why here? unnatural */ + rb_progname = progname; + } } if (opt->src.enc.index >= 0) { enc = rb_enc_from_index(opt->src.enc.index); -- Yusuke Endoh ---------------------------------------- http://redmine.ruby-lang.org/issues/show/1573 ---------------------------------------- http://redmine.ruby-lang.org