Question about -K, $KCODE, command line


#1

Hi all,

If I run a program from the shell like “ruby test.rb -K u”, why isn’t
$KCODE set within the program to “UTF8”?

test.rb

puts $KCODE

ruby test.rb -K u -> “NONE” ???

It looks like the only way to change it is to assign to $KCODE directly
within the program. Why? Would changing $KCODE from a command line
option have unintended side effects?

Dan


#2

On Sat, 2006-05-27 at 03:38 +0900, Daniel B. wrote:

It looks like the only way to change it is to assign to $KCODE directly
within the program. Why? Would changing $KCODE from a command line
option have unintended side effects?

You need -Ku, not -K u. The K is being taken as empty, and the ‘u’ is
being passed as an argument to your script.

$ ruby -Ku -e ‘puts $KCODE’
UTF8
$ ruby -e ‘puts $KCODE’ -Ku
UTF8


#3

Ross B. wrote:

UTF8

I tried that.

Actually, my real problem was that I was putting the option after
the program name. DUH!

Thanks,

Dan