I want to read the error codes or the exit status of awk script into shell to use in if condition to compare for error handling my shell script looks something like:
My script:
#!/bin/sh
awk -v CONFIG_SOURCE=Testfile1.txt -f test.awk
echo $? # prints the error code '2' in this case, if the file is actually not available
recval = $?
if ($recval == '$2') **//this condition statement doesn't seems to work.**
then
echo "Some error"
fi
test.awk file:
BEGIN {
ignore_line = 0;
if ( CONFIG_SOURCE == "" )
{
print "Error: Invalid embed source file.";
exit 1
}
if ( 0 != system( "[ -f " CONFIG_SOURCE " ] " ) )
{
print "Error: Embed source file '" CONFIG_SOURCE "' does not exist."
exit 2
}
}
So, if the file is not available, it will return exit status '2',which i can echo but,how to copy the value '2' or the exit status to some variable(recval) in shell)