Linux Shell Basics

Source: Internet
Author: User
Tags file permissions

some things to note about shell script:1, #这个符号是注释本行, usually used for annotations, #! Except that it is used to label which Shell executes this script,2, the order of execution from top to bottom, from the right3, ignoring blank lines, tab spaces4, script wrap with \ And then continue to write code on the next line shell script performs the required permissions chmod755or Chomod r+.x is all you can. Shell script executes three methods1, SH Script_path This method executes, the variables outside the script are not drinkable2, and used in this directory.script_name "Recommended use"3, source script_path good habits of shell annotations1, you need to annotate the shell's functionality2, comment version information3, annotated author and contact information4, Copyright Declaration5, a simple history change record6, run environment variable declaration notice in addition, important code snippets also use annotations, to increase readability and maintainability of the interactive script (to talk) read instructions, can be very good to get user input and assign value to the specified variable example: Read-P "Please enter your name" FirstName This window will prompt you to enter, the disease assigns your content to the first variable to continue to run. The following script will be able to use the variable srcipt file name according to date processing, dynamic get log stitching specified string can form their own desired canonical standard document name, usually used in backup files and other functions. Date Directive Common Date+%y%m%d Assignment to variable example: Date1=$ (Date +%y%m%d) #今天日期 date2=$ (Date--date='2 days ago'++%y%m%d) Define the A variable and the b variable instruction $ ((${a}) #2天前日期shell the basic operation method in the Scipt.*${b})) Use judgment, skillfully using the shell's own variables to find problems such as $?represents the previous command execution of the demerit, the success of 0echo $?you can see the test command, the direct judgment method, very useful to determine the directory-D judgment file-E or-F Example: Test-F index.html && Echo"exist"|| Echo"Not exist"The description determines whether the current directory index.html file exists, the output exit is present, otherwise the output is not exist&&The meaning of success is to execute the following instruction, otherwise skip. Some common flags for common testing of files or directories-e determine the file or directory-F Judging Ordinary files-d determine the common method of judging the directory file permissions-R to Judge readable-W judgment can be written-x to determine the executable-s determines whether a non-blank document file is more commonly used-NT judgment File New 1:2 new-ot judging files old 1:2 old-whether EF is the same file integer value judgment-is EQ equal to-ne is not equal to-GT greater than-LT is less than-GE is greater than or equal-Le is less than or equal to string data judge Test-Zstringdetermine if the test is empty-Nstringdetermine if it is not a 0test str1==str2 string is equal to test str1! =str2 whether strings are unequal or and-A and Judgment-O or Judge! Reverse judgment exit can automatically return the result how to judge? 1, test command plus option plus parameters2, [options + parameters]; For example [-F file1.txt];echo"XXX", notice that each component in this area is separated by a space $# $0$1$2$3$4[Email protected] represents the number of parameters, script name, parameter 1, parameter 2, parameter 3, parameter 4, all parameters if common judgmentif; then commandif

Linux Shell Basics

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.