R: pass variable from R to unix -
i running r script via bash script , want return output of r script bash script keep working there.
the bash sth this:
#!/bin/bash rscript myrscript.r a=output_from_myrscript.r sth
and r script sth this:
for(i in 1:5){ sink(type="message") }
i want bash work 1 variable r @ time, meaning: bash receives i=1 , works that, when task done, receives i=2 , on.
any ideas how that?
one option make r script executable #!/usr/bin/env rscript
(setting executable bit; e.g. chmod 0755 myrscript.r
, chmod +x myrscript.r
, etc...), , treat other command, e.g. assigning results array variable below:
myrscript.r
#!/usr/bin/env rscript cat(1:5, sep = "\n")
mybashscript.sh
#!/bin/bash res=($(./myrscript.r)) elem in "${res[@]}" echo elem "${elem}" done
nrussell$ ./mybashscript.sh elem 1 elem 2 elem 3 elem 4 elem 5
Comments
Post a Comment