Linux Shell Learning Notes

Source: Internet
Author: User
Tags diff sqoop

Difference between 2.return and exit

    • Return means returning from the function returned to the main key function to continue execution, the return can be accompanied by a return value, specified by the argument after return, of course, if it is in the primary function main, it will naturally end the current process, if not, it is to return to the previous layer of the call.
    • Exit (0) indicates the normal exit execution program, if plus other values: 1, 2, .... Can indicate that a different error causes the exit.
    • Exit (0) in the main function is equivalent to return 0.

1. Linux the next command or process execution completes returns a status code.

0 = = = Successful execution of non-0 = = = Unexpected or abnormal exit during execution
    • The last command executed in the shell script will determine the state of the entire shell script.
    • The shell's internal command exit can also terminate the execution of the shell script at any time, returning the shell script's status code.
    • When the last command before the execution of the shell script is exit with no arguments, the final return value of the shell script is the return value of the previous statement in the Exit statement, which allows you to determine whether the script executed successfully or not.
    • $? You can view the return value of the last command this variable can be used anywhere in the shell script.

2 Segment Sample Code

#! /bin/BashEcho "Please input the branch want to compare"Read $MY _branch forIinch$(Catlist) Dogit-diff--quiet $MY _branch $i [--The quiet option means not to output the results of the diff after comparison .if[$?-eq0]        [$?is the status code executed by the previous command] Then              Echo$ifi Done
#!/bin/Bashif[!-N" $"] ; Then    Echo "sqoop1.sh missing 1 parameter:db.properties."    Echo "Usage:./xxx.sh db.properties"Exit2Else    Echo "The sqoop season is running ..."Eval 'Cat./db.properties ' sqoop import--append--connect $url--username $username--password $password--target-dir$targetDir--m $num--table $table--fields-terminated-by'$deco'--where"cur_date like ' $Jan% ' or cur_date like ' $Feb% ' or cur_date like ' $Mar% '"> LogSqooq1.log2>&1
# Exit 200fi

A description of the 2nd shell script above:

1. Enter if, the return value is 2, if all the Sqoop command is running normally, the return value is 0, if the Sqoop command executes an exception, the return value is non 0.

2. If the 11th line adds exit 200, the return value is 200 regardless of whether the Sqoop statement performs an exception or not.

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.