From: Lloyd Zusman Date: 2007-02-11T00:56:45+09:00 Subject: Re: ENV['COLUMNS'] Brian Candler writes: > On Sat, Feb 10, 2007 at 10:56:35PM +0900, Lloyd Zusman wrote: >> > This is a shell-internal variable, and not exported by default to processes >> > launched from the shell. But it can be if you wish: >> >> Well, if that were the case, the variable wouldn't be visible within >> irb, either. Since it is, then it must be an exported environment >> variable and not just shell internal. > > Well, on my system: > > brian@mappit:~$ irb1.8 > irb(main):001:0> ENV.size > => 39 > irb(main):002:0> exit > brian@mappit:~$ ruby1.8 -e 'puts ENV.size' > 37 > brian@mappit:~$ printenv | wc -l > 37 > brian@mappit:~$ > > So my guess is that irb is setting these variables itself, or calling some > library which does so (readline perhaps?) Yes, it looks like the shell is not exporting those environment variables, after all. Therefore, I agree that it's probably irb who is setting and exporting them. If you're running under Linux and you need these variables to be exported, you could eval the /usr/bin/resize command as part of your shell startup commands. In bash, for example, you could put the following into your ~/.bash_profile or ~/.bash_login: eval `/usr/bin/resize` This will ensure that all of your interactive shells will have these variables set and exported, so you can then find them inside of the ENV object within ruby. ... or you could even put this into /etc/profile, to ensure that all interactive users get these variables exported to their interactive shells during login. If you want to query these values directly from ruby without relying on externally set environment variables, and if you know you're going to always be running under Linux, check this out: http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/40350 >> I think that the problem has to do with how script.rb is being invoked. >> Is it started from something other than a terminal session? ... perhaps >> via a cron job or a startup daemon? If so, then LINES and COLUMNS would >> not normally be set, since those environment variables are usually >> initialized and exported only within an interactive shell. > > I thought of that, but all the examples shown above and in my previous reply > were typed into a terminal session. > > Regards, > > Brian. > > -- Lloyd Zusman ljz@asfast.com God bless you.