How to get exit status of R script run in shell script

2.5k views Asked by At

Suppose I'm running a Rscript from inside this shell script

#!/bin/bash
RES=$(./abc.R 100)
r_status=echo $?

There is some code in abc.R which stops its execution

#!/usr/bin/env Rscript
...
...
if(nrow(status) == 0)
{ stop("The list id is not present in requests table. Please check.") } else if (status != 'COMPLETED')
{ stop("The list is not in COMPLETED state. Please check.")}
...
...

I am not able to capture the exit status of abc.R in my shell script. It stops R execution and even quits from the shell script to the prompt.

Is there any way I can capture R's exit status.

1

There are 1 answers

1
Mosh Yaz On

Just run the script you want. make sure it returns the correct exit status when finishing its run. This should work:

#!/bin/bash
./abc.R 100
if  [ $? == 0 ]; then
  echo "Your script exited with exit status 0"
  exit 0

see more here: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_08_02.html