I'm currently using bash 4.1 and I'm using a function to perform a SVN cat on a repository file. After that, it iterates over each line to perform some transformations (mostly concatenations and such). If said file does not exist, the script should stop with an error message. The script is as follows:
function getFile {
svnCat=`svn cat (file) 2>&1`
if [[ -n $(echo "$svnCat" | grep "W160013") ]]; then # W160013 is the returned value by SVN stderr case a file doesn't exist
echo "File doesn't exist" >&2
exit 1
else
echo "$svnCat" | while read -r; do
#Do your job
done
fi
}
function processFile{
while read -r do
#do stuff
done < <(getFile)
#do even more stuff
}
However, in situations where a file does not exist, the error message is printed once but the script keeps executing. Is there a way to detect that the while looped failed and should stop the script completely?
Can't use set -e option since I require to delete some files that were created in the process.
Update: I've tried to add || exit after the done command as follows:
function processFile{
while read -r do
#do stuff
done || exit 1 < <(getFile)
However, the script is waiting for user output and when I press enter, it executes the content in the while loop