Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby cannot see NLS_LANG environmental variable

Tags:

bash

ruby

oci8

I'm running a ruby script on CentOS, and installed ruby via rvm (1.9.3).

I've set the NLS_LANG variable in .bash_profile.

[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:

 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.

Thing is I'm running sqlplus from the ruby script (to execute some .sql files), and special characters are all messed up.

How can I get ruby to see the value?

like image 414
robertrv Avatar asked May 11 '12 20:05

robertrv


People also ask

What command will you use to find the value of the system environment variable Nls_lang?

You can view the NLS_LANG setting by entering the SELECT command: SELECT * FROM NLS_SESSION_PARAMETERS; The NLS_TERRITORY and NLS_LANGUAGE values correspond to the language and territory components of the NLS_LANG variable.

What is Nls_lang?

NLS_LANG is set as a local environment variable on UNIX platforms. NLS_LANG is set in the registry on Windows platforms. The NLS_LANG parameter has three components: language, territory, and character set. Specify it in the following format, including the punctuation: NLS_LANG = language_territory.charset.


1 Answers

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 LANG should be available:

export NLS_LANG=$LANG
like image 59
mpapis Avatar answered Sep 28 '22 19:09

mpapis