0

I'm fetching data from a 4 column table. If all the 4 columns have some kind of data (not empty), then it is working. If, by any chance, one of the columns is null then it's going to throw an error. From the table the name of file is fetched and file is saved in one directory of the server and that file is being emailed.

What I need to do is, suppose one column is null and the other 3 columns are not null then it should send the remaining file rather going to error.

2 Answers 2

3

Assuming you're using bash, you can use || and && conditions because there is no try/catch in bash. For example:

Run command2 if command1 fails:
command1 || command2

 

Run command2 if command1 is successful:
command1 && command2
Sign up to request clarification or add additional context in comments.

Comments

1

To check return code of a last command use this variable: $?

For example:

echo "abc" > /dev/null
echo $? 

returns 0 which means no error

when you have error:

cat /etc/shadow
cat: /etc/shadow: Permission denied
echo $?

returns 1 which is error, usually every nonzero return code is an error.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.