Reputation: 3663
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
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