Detection and return code of unixshell learning

Source: Internet
Author: User
When unixshell detects the returned code and runs any command, linux returns the response related to the execution of the previous command, called the return code (returncode). how can this code be returned? Simple. use $? You can view the results. you can view the results. if the command successfully runs the unix shell learning check and returns the code. when you run any command, linux returns the response of the previous command execution, it is called return code. how can I get back to the code? Simple. use $? You can view it. you can view it. if the command is successfully executed, the return code is 0. if the command is not successfully executed, a value other than 0 is returned. We can use a small example in the book to perform a test. the following code writes three different if statements to better learn shell, but their functions are the same. #! /Bin/bashtest-d/usr/local/binif ["$? "-Eq 0] then echo"/usr/local/bin exist! "Else echo"/usr/local/bin does not exist! "Fi # --------------------------------------- if test-d/usr/local/binthen echo"/usr/local/bin exist! "Else echo"/usr/local/bin does not exist! "Fi # ------------------------------------- if [-d/usr/local/bin] then echo"/usr/local/bin exist! "Else echo"/usr/local/bin does not exist! "Fi
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.