From: gotoken@... (GOTO Kentaro) Date: 1999-08-04T00:44:48+09:00 Subject: [ruby-list:15867] Re: cannot install ruby-gtk into FreeBSD 2.2.x --Multipart_Wed_Aug__4_00:44:12_1999-1 Content-Type: text/plain; charset=ISO-2022-JP ごとけんです In message "[ruby-list:15855] Re: cannot install ruby-gtk into FreeBSD 2.2.x" on 99/08/03, Katsuyuki Komatsu writes: ># まだ、ここまでする必要があるかという件に結論は出ていませんが…… えーっとえーっとわたなべさんもいうように今の問題は別にしても $^X が欲しいというのはあったりしますよね ^^; # しかしまつもとさんは今日はいないんだっけ。実装的に問題なけ # れば [ruby-list:15843] は採用して欲しいのだけど。もう無理?? > RUBY = #{CONFIG["ruby_install_name"]} >を > ruby_interpreter = File.expand_path(`which #{RUBY_INTERPRETER}`) > …… > RUBY = #{ruby_interpreter} >にすればいいわけですが、whichを呼ぶのはよろしくないので、 >相当するルーチンがあればよいかと。 > >ありましたっけ? それは気になってはいましたが、UNIXモデルでは実行ファイルが自 身の場所を知る方法ってないと思うです、たぶん。ってわけで書い てみました。File::which("ls") => ["/bin/ls"] というものです。 # FreeBSD の /usr/bin/which が perl だったのが悔しくて ^^;; 上の場合だと、 ruby_interpreter = File.expand_path(File.which(RUBY_INTERPRETER)[0]) もちろんご指摘の通り ./ruby -X dir には対応しませんので、-X なら絶対パスでインタプリタを起動するか、-X のリストをもらう 必要があります。 --Multipart_Wed_Aug__4_00:44:12_1999-1 Content-Type: application/octet-stream Content-Disposition: attachment; filename="which.rb" Content-Transfer-Encoding: 7bit #!/usr/local/bin/ruby class << File def which(target, all = false) path = ENV['PATH'].split(':') res = [] for prog in target if (prog =~ '/') && test(?x, prog) && test(?f, prog) res.push prog else for e in path cmd = "#{e}/#{prog}" if test(?x, cmd) && test(?f, cmd) res.push cmd break unless all end end end end res end end if __FILE__ == $0 all = silent = found = false if ARGV[0] == '-a' all = true; ARGV.shift elsif ARGV[0] == '-s' silent = true; ARGV.shift elsif ARGV[0] =~ /^-((h)|(help)|\\?$)/ stderr.puts "usage: which [-a] [-s] program ..." exit end res = File::which(ARGV, all) puts res unless silent exit (res.empty? ? 1 : 0) end --Multipart_Wed_Aug__4_00:44:12_1999-1 Content-Type: text/plain; charset=ISO-2022-JP >mswin32では、常にフルパスがくるので、 > RUBY = #{RUBY_INTERPRETER} >でよいですけどね。 それはそれで便利な仕様ですね。 -- gotoken --Multipart_Wed_Aug__4_00:44:12_1999-1--