シェルスクリプト test.sh の内容

#!/bin/bash
r --vanilla --slave < test.R

# コマンドの直後に、終了コードを見る
echo $?