Username
Username

Reputation: 3663

How do I use Bash to get a Ruby variable?

I have a Ruby script called script.rb, which looks like this:

puts 16

I have a Bash script that looks like this:

#!/bin/bash
SOME_VARIABLE=$(ruby script.rb)

I want SOME_VARIABLE to be equal to 16, or whatever else I decide to puts from script.rb.

How do I do this?

Upvotes: 1

Views: 602

Answers (1)

Nabeel
Nabeel

Reputation: 2302

You can use it as such.

#!/bin/bash
SOME_VARIABLE=`ruby script.rb`

If for example you want to export an environment variable.

export SOME_ENV=`ruby script.rb`
$ echo $SOME_ENV
16

More information on command substitution.

Upvotes: 3

Related Questions