Is it possible to return a value from a ruby ​​script and read that value inside c or shell script?

How to return value from ruby ​​script?

#!/usr/bin/env ruby

a = "test"
a

How can we access the value of 'a' in an Ubuntu or java or c terminal?

+4
source share
2 answers

print your variable in ruby ​​/ python script, then it can be read from the shell script using an example:

#!/bin/bash
ruby_var=$(ruby myrubyscript.rb)
python_var=$(python mypythonscript.py)

echo "$ruby_var"
echo "$python_var"

make sure that your ruby ​​/ python script prints only this variable (there are more complex ways with named pipes in the example for more interaction).

+6
source

If the value is an integer from 0 to 255, you can use the exit status

$ ruby -e 'var=42; exit var'
$ val=$?
$ echo $val
42
+4

All Articles