Getting command line

J

Joe Van Dyk

Hi,

If I launch a Ruby process with:
ruby something.rb lots of "stuff here" and I want all 'of it'

How can I get a string from inside the ruby process with:
lots of "stuff here" and I want all 'of it'
in it?
 
T

Timothy Hunter

Joe said:
Hi,

If I launch a Ruby process with:
ruby something.rb lots of "stuff here" and I want all 'of it'

How can I get a string from inside the ruby process with:
lots of "stuff here" and I want all 'of it'
in it?
ARGV is an array of the tokens on the command line that follow the name
of the script. If you want them all in one string you can use the join
method to join them together.

puts ARGV.join(' ')
 
A

ara.t.howard

Hi,

If I launch a Ruby process with:
ruby something.rb lots of "stuff here" and I want all 'of it'

How can I get a string from inside the ruby process with:
lots of "stuff here" and I want all 'of it'
in it?

you can't. the " and ' are handled by the shell.

ARGV.join will give you

[ "lots", "of" "stuff here", "and", "I", "want", "all", "of it"]

note - the quotes will be lost.

read up on bash 'word splitting' and 'quote removal' for more info

http://www.gnu.org/software/bash/manual/bashref.html#SEC36
http://www.gnu.org/software/bash/manual/bashref.html

regards.

-a
 
H

Hal Fulton

Timothy said:
ARGV is an array of the tokens on the command line that follow the name
of the script. If you want them all in one string you can use the join
method to join them together.

puts ARGV.join(' ')

Of course, if you (the OP) want the quotes, you'll have to escape
them or the shell will strip them.


Hal
 
J

Joe Van Dyk

Hi,

If I launch a Ruby process with:
ruby something.rb lots of "stuff here" and I want all 'of it'

How can I get a string from inside the ruby process with:
lots of "stuff here" and I want all 'of it'
in it?

you can't. the " and ' are handled by the shell.

ARGV.join will give you

[ "lots", "of" "stuff here", "and", "I", "want", "all", "of it"]

note - the quotes will be lost.

read up on bash 'word splitting' and 'quote removal' for more info

http://www.gnu.org/software/bash/manual/bashref.html#SEC36
http://www.gnu.org/software/bash/manual/bashref.html

regards.

Oh yeah, I forgot that the shell automatically escapes stuff. Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,214
Messages
2,571,112
Members
47,704
Latest member
DavidSuita

Latest Threads

Top