#!/bin/bash -x #input is an empty text file with the date to be processed in the filename, e.g. date_2003-01-01.txt input=$1 indir=$2 outdir=$3 Rfile=$4 date=$(basename $input .txt | cut -d'_' -f2) yr=${date:0:4} dir_to_search=${indir}/_monthly_sum/ cp ${dir_to_search}/swat_${yr}*.tif . if [ ! -f ${outdir}/swat_${yr}.tif ]; then mkdir -p output/ #run r script to calculate frequency of surface water occurrence echo "Rscript $Rfile $yr swat" Rscript $Rfile $yr swat mv swat_${yr}.tif output/swat_${yr}.tif else echo "${outdir}/swat_${yr}.tif already exists" fi exit 0