Cshell script setting up a flag
Currently I am doing this on my script..
if($notLoaded1 > 0) then
echo "Rows not loaded due to data errors: $notLoaded1"
exit 1
endif
if($notLoaded2 > 0) then
echo "Rows not loaded due to data errors: $notLoaded2"
exit 1
endif
if($notLoaded3 > 0) then
echo "Rows not loaded开发者_StackOverflow社区 due to data errors: $notLoaded3"
exit 1
endif
How can i set up a flag so it won't exit on the first if statement, goes through all of them and lets me know like which other if statement had problem too.. Thank you.. Someone please help me with this .. I am new to this
why not simply define a variable 'flag' and use the && operator setting it to 0 if you don't want to exit:
$flag && exit 1
Try this
set errorFlag=0
if ($notLoaded1 > 0) then
echo "Rows not loaded due to data errors: $notLoaded1"
set errorFlag=1
endif
if ($notLoaded2 > 0) then
echo "Rows not loaded due to data errors: $notLoaded2"
set errorFlag=1
endif
if ($notLoaded3 > 0) then
echo "Rows not loaded due to data errors: $notLoaded3"
set errorFlag=1
endif
if ($errorFlag != 0) then
exit 1
endif
I don't have access to a csh environment now, so I can't test this. I'm not absolutely sure about the !=
test, so you can also use $errorFlag > 0
.
I hope this helps.
精彩评论