bash Ruby 看不到 NLS_LANG 环境变量
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10558439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Ruby cannot see NLS_LANG environmental variable
提问by robertrv
I'm running a ruby script on CentOS, and installed ruby via rvm (1.9.3).
我在 CentOS 上运行 ruby 脚本,并通过 rvm (1.9.3) 安装了 ruby。
I've set the NLS_LANG variable in .bash_profile.
我在 .bash_profile 中设置了 NLS_LANG 变量。
[app@box stasis]$ echo $NLS_LANG
en_US.UTF-8
[app@box stasis]$ which ruby
~/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
However when trying to access it via ruby (which the oci8 driver does), it cannot find it:
但是,当尝试通过 ruby(oci8 驱动程序这样做)访问它时,它找不到它:
1.9.3-p194 :001 > ENV['NLS_LANG']
=> nil
Accessing other vars seems to work:
访问其他变量似乎有效:
1.9.3-p194 :004 > ENV['USER']
=> "app"
My script shows the following: Warning: NLS_LANG is not set. fallback to US7ASCII.
我的脚本显示如下: Warning: NLS_LANG is not set. fallback to US7ASCII.
Thing is I'm running sqlplus from the ruby script (to execute some .sql files), and special characters are all messed up.
事情是我从 ruby 脚本运行 sqlplus(执行一些 .sql 文件),并且特殊字符都搞砸了。
How can I get ruby to see the value?
我怎样才能让红宝石看到价值?
回答by mpapis
You need to export your variables to be available in any applications run (unless they are functions):
您需要导出变量以在任何应用程序运行中可用(除非它们是函数):
export NLS_LANG
or together with setting:
或与设置一起:
export NLS_LANG=en_US.UTF-8
or as on most systems LANGshould be available:
或者在大多数系统上LANG应该可用:
export NLS_LANG=$LANG

