How Ruby environment varibles work in realtime program?

Hi,

I just introduced myself to the below the environment variables:

DLN_LIBRARY_PATH,HOME,LOGDIR,RUBYOPT,RUBYSHELL

Now m question is does these variables keep with them any constant value
or the values are loaded on run time?

Can you give me a small snippet by which I can understand each of the
environment variable how works in real-time application?

Anyway to show the values of those variables if they are containing
static values?

Thanks

···

--
Posted via http://www.ruby-forum.com/.

Now m question is does these variables keep with them any constant value
or the values are loaded on run time?

I am not sure I understand what you are asking. The Ruby interpreter,
like any other process, inherits environment variables from the
calling process. If it changes values of those variables those
changes are again inherited by processes started by the interpreter.

Can you give me a small snippet by which I can understand each of the
environment variable how works in real-time application?

What do environment variables have to do with realtime applications?
I don't see any specific different handling of environment variables
in realtime and non realtime applications.

Anyway to show the values of those variables if they are containing
static values?

What do you mean by "static"? Since they are variables their values
can change - any time.

Kind regards

robert

···

On Fri, Jan 11, 2013 at 1:41 PM, Arup Rakshit <lists@ruby-forum.com> wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

I should think
[DLN_LIBRARY_PATH, HOME, LOGDIR, RUBYOPT, RUBYSHELL].each {|var| puts
var }
would suffice to check them all whenever you want.

···

--
Posted via http://www.ruby-forum.com/.

Oops, forgot the dollar signs. FYI that's a single line of code, it gets
put onto 2 lines by a line character limit on the forum.

[$DLN_LIBRARY_PATH, $HOME, $LOGDIR, $RUBYOPT, $RUBYSHELL].each {|var|
puts var }

When I run that in IRB they all come out as nil, presumably because in
that environment they aren't set.

···

--
Posted via http://www.ruby-forum.com/.

Jeremy's answer is right, I got confused about what variables you were
looking at.

···

--
Posted via http://www.ruby-forum.com/.

Robert Klemme wrote in post #1091908:

···

On Fri, Jan 11, 2013 at 1:41 PM, Arup Rakshit <lists@ruby-forum.com> > wrote:

Now m question is does these variables keep with them any constant value
Anyway to show the values of those variables if they are containing
static values?

What do you mean by "static"? Since they are variables their values
can change - any time.

Kind regards

robert

`static` value means i tried to say if those variables having values at
the time Ruby installations. But now is there any way to check what the
values of such variables containing at any point of time. Any specific
command.

Note: I am using Windows - 7

Thanks

--
Posted via http://www.ruby-forum.com/\.

Joel Pearson wrote in post #1091923:

I should think
[DLN_LIBRARY_PATH, HOME, LOGDIR, RUBYOPT, RUBYSHELL].each {|var| puts
var }
would suffice to check them all whenever you want.

I am getting the below error:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\rakshit>irb
irb(main):001:0> [DIN_LIBRARY_PATH,HOME,LOGDIR,RUBYOPT,RUBYSHELL].each
{|var|put
s var }
NameError: uninitialized constant DIN_LIBRARY_PATH
        from (irb):1
irb(main):002:0> [DLN_LIBRARY_PATH,HOME,LOGDIR,RUBYOPT,RUBYSHELL].each
{|var|put
s var }
NameError: uninitialized constant DLN_LIBRARY_PATH
        from (irb):2
irb(main):003:0> ^C
irb(main):003:0> exit
Terminate batch job (Y/N)? y

C:\Documents and Settings\rakshiar>

···

--
Posted via http://www.ruby-forum.com/\.

You're in Ruby here, not bash, so those names are global variable
references for variables that haven't been defined. Therefore they
default to nil. See my earlier reply for what you really intended to
do. :slight_smile:

-Jeremy

···

On 01/11/2013 08:54 AM, Joel Pearson wrote:

Oops, forgot the dollar signs. FYI that's a single line of code, it gets
put onto 2 lines by a line character limit on the forum.

[$DLN_LIBRARY_PATH, $HOME, $LOGDIR, $RUBYOPT, $RUBYSHELL].each {|var|
puts var }

When I run that in IRB they all come out as nil, presumably because in
that environment they aren't set.

These are global variables and not environment variables! Please see
Jeremy's reply for how to access environment variables.

Kind regards

robert

···

On Fri, Jan 11, 2013 at 3:54 PM, Joel Pearson <lists@ruby-forum.com> wrote:

Oops, forgot the dollar signs. FYI that's a single line of code, it gets
put onto 2 lines by a line character limit on the forum.

[$DLN_LIBRARY_PATH, $HOME, $LOGDIR, $RUBYOPT, $RUBYSHELL].each {|var|
puts var }

When I run that in IRB they all come out as nil, presumably because in
that environment they aren't set.

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Joel Pearson wrote in post #1091935:

Oops, forgot the dollar signs. FYI that's a single line of code, it gets
put onto 2 lines by a line character limit on the forum.

What the reason could be of not set the variables? and how should I need
to set such variables?

Too much confused! :frowning:

···

--
Posted via http://www.ruby-forum.com/\.

As you can see, Ruby thinks those names you specified are constants, but
you need them to be strings in this case. You also need to look up
their values via the ENV hash:

%w(DIN_LIBRARY_PATH HOME LOGDIR RUBYOPT RUBYSHELL).each do |var|
  puts "#{var}=#{ENV[var]}"
end

The %w above takes a string defined between the parenthesis and splits
it on whitespace. The result is an array of strings that we then
iterate over. Then we print the variable name and the value of that
variable from the environment via the ENV hash.

-Jeremy

···

On 01/11/2013 08:14 AM, Arup Rakshit wrote:

Joel Pearson wrote in post #1091923:

I should think
[DLN_LIBRARY_PATH, HOME, LOGDIR, RUBYOPT, RUBYSHELL].each {|var| puts
var }
would suffice to check them all whenever you want.

I am getting the below error:

Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\rakshit>irb
irb(main):001:0> [DIN_LIBRARY_PATH,HOME,LOGDIR,RUBYOPT,RUBYSHELL].each
{|var|put
s var }
NameError: uninitialized constant DIN_LIBRARY_PATH
        from (irb):1
irb(main):002:0> [DLN_LIBRARY_PATH,HOME,LOGDIR,RUBYOPT,RUBYSHELL].each
{|var|put
s var }
NameError: uninitialized constant DLN_LIBRARY_PATH
        from (irb):2