Linux shell programming-shell judgment

Source: Internet
Author: User

Linux shell programming ---- Judge 1 test in shell to Judge 1 test-f $ file name to determine whether the file exists test-f $ file name. Example: Use the test-f command to find the input.txt file in the/homedrop folder, if exist is output, otherwise, no exist 2 is output, and there are many other commands: 1 test-d $. The directory name determines whether the directory exists. 2 test-r $ the file name determines whether the file has the read permission. 3 test-w $ the file name determines. whether the file has the write permission 4 test-x $ whether the file has the execution permission 2 [[Judge 1 must be separated by spaces in brackets, for example, ['10' <'20'] this judgment, it is better to have four spaces in the brackets. 2. Enclose the variables in double quotation marks. a = "this" B = "this is" for example, ["$ "! = "$ B"] 3 constant in brackets, it is best to enclose them in single quotes, for example, ['4' = '4'] 3 (the following is just an example of [], or test, only [] Looks beautiful) 1. Single Branch judgment structure if []; then statement fi 2 dual Branch judgment structure if []; then statement else statement fi 3 multi-branch judgment structure if []; then statement elif []; then statement else statement fi 4 case realize multi-branch judgment structure case $ Variable in condition 1) statement; condition 2) statement; Condition 3) statement ;;............................. *) statement; esac

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: 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.