# Question about -K, $KCODE, command line

**URL:** <https://www.ruby-forum.com/t/question-about-k-kcode-command-line/61745>\
**Category:** Ruby\
**Created:** [May 26, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/question-about-k-kcode-command-line/61745 "2006-05-26T20:42:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 26, 2006, 8:42pm UTC](https://www.ruby-forum.com/t/question-about-k-kcode-command-line/61745/1 "2006-05-26T20:42:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 26, 2006, 9:01pm UTC](https://www.ruby-forum.com/t/question-about-k-kcode-command-line/61745/2 "2006-05-26T21:01:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![danielb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/c57346/32.png) [@danielb](https://www.ruby-forum.com/u/danielb)\
**Post date:** [May 26, 2006, 9:20pm UTC](https://www.ruby-forum.com/t/question-about-k-kcode-command-line/61745/3 "2006-05-26T21:20:21Z")

</div>

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
