Shell statement error or abnormal auto Exit Do not continue execution

Source: Internet
Author: User

Today's operation encountered a problem, need to redirect the content to the file, and then rename the use of the file, the result of the redirection has been thrown out of the exception, the following nature will be followed by a variety of problems. Therefore, it is still felt that some key operations to make some judgments or catch exceptions, to avoid the emergence of more serious problems.

The solution is as follows:

Using SET-E
The beginning of every script you write should contain set-e. This tells Bash to exit bash if any one of the statements returns a value that is not true. The advantage of using-e is to avoid making the error snowball into a serious error and catching the error as early as possible. More readable version: Set-o Errexit uses-E to free you from inspection errors. If you forget to check, bash will do it for you. But you have no way to use $? To get the command execution status because bash cannot get any return values that are not 0. You can use a different structure, using the command
Use command
If ["$?" -ne 0]; Then echo "Command failed"; Exit 1; Fi "can be replaced by: command | |  

Shell statement error or abnormal auto Exit Do not continue execution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.