Forum: Ruby Question about -K, $KCODE, command line

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (Guest)
on 2006-05-26 20:42
(Received via mailing list)
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
A9b6a93b860020caf9d2d1d58c32478f?d=identicon&s=25 Ross Bamford (Guest)
on 2006-05-26 21:01
(Received via mailing list)
On Sat, 2006-05-27 at 03:38 +0900, Daniel Berger 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
Aee77dba395ece0a04c688b05b07cd63?d=identicon&s=25 Daniel Berger (Guest)
on 2006-05-26 21:20
(Received via mailing list)
Ross Bamford wrote:
>>
> UTF8
>

I tried that.

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

Thanks,

Dan
This topic is locked and can not be replied to.