1

I have a Rscript which generates several variables. I would like to import one of these variables into a bash loop? Is it possible?

My variable is variable and I want to import it like this :

for i in variable
do <command line>
done 

I do not want to save variable into a file and reload this .

Is there a solution?

1
  • A workaround would be to write that variable in a textfile and use textfile as input in your bash script. Commented May 20, 2019 at 11:36

1 Answer 1

1

You can have the R script print out the content of the variable and use a construct like this:

VAR=$(Rscript myscript.R)
for i in $VAR
do <command line>
done 
Sign up to request clarification or add additional context in comments.

3 Comments

What if there are more than one variable in mycript.R ?
As a general rule, you cannot create variables in the environment of the parent script. You need either to use files, pipes, or, as suggested in the answer, inline evaluation.
I saved my variable into a file and I reuse this file later. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.