LinuxShell programming learning Notes

Source: Internet
Author: User
LinuxShell programming learning notes log on to Shell, the Shell program automatically loaded after you log on to the system. most Linux systems use/bin/bash as the shells that can be used by the Shell system supported by the default logon Shell/etc/shells file system, record in/etc/shells... linux Shell programming learning notes log on to Shell, the Shell program automatically loaded after you log on to the system. most Linux systems use/bin/bash as the shells that can be used by the Shell system supported by the default logon Shell/etc/shells file system, the last data record of cat/etc/shellsecho $ SHELL/etc/passwd in the/etc/shells file is the shell script written by the user login. note: 1. the command is to analyze and execute 2. if you read the Enter symbol, try to execute this line. Command 3. you can use \ [Enter] for branch 4. # execute the/home/zack/shell script for annotation execution. sh: 1. run the following command: shell. sh files must have the r and x permissions. 2. run the following command in bash: bash shell. sh or sh shell. shshell. sh only requires the r permission. 3. use source to execute, execute special characters in The Parent Program double quotation marks to allow reference, \ escape single quotes to prohibit reference, escape anti-apostrophes, or $ () replace the status value of the previous command with command output $? 0 is a normal, non-0 exception expr command, calculation expression such as: expr 45-32 expr 12/* 11 $ [] expression, formula replacement such: echo $[45 + 12] x = 45; y = 11; echo $ [x-y] variable increments, decrease let variable name + let variable name -- let variable name + = 2 RANDOM number echo $ RANDOMecho $ [RANDOM % 100] $ (seq 1 100) # seq is sequence (continuous) abbreviation, from 1 to 100 consecutive number seq first number Last number seq first number increment last number generate random string head-n 1/dev/urandom | md5sum | cut-B 1-8 test Command the test command is used to detect certain files or attributes in the system. The brackets "[]" are used for judgment, for example: ["$ HOME" = $ "MAIL"] ["$ yn" = "N"-o "$ yn" = "n"]-e existence-f Whether file-d is Directory-r read permission read-w write permission write-x execution permission excution-z is empty-eq is equal to-ne not equal to-gt is greater than-lt less- ge is greater than or equal to-le is less than or equal! No script parameter scriptname opt1 opt2 opt3 opt4 $0 $1 $2 $3 $4 $ # number of parameters $ @ all content of the parameter if judgment statement if []; then elif []; thenfi case judgment 1. start with case and end with esac 2. each variable is enclosed in double quotes and ended with parentheses. the program section ends. use * to represent other values case $ variable names in <= The keyword is case, and there is also a rich front variable font size "the first variable content ") <= It is recommended that the content of each variable be enclosed by double quotation marks, and the keyword is parentheses). <= two consecutive semicolons are used at the end of each class deletion! "Second variable content") program segment; *) <= the last variable content uses * to represent all other values, other program execution segments that do not contain the content of the first variable and the content of the second variable exit 1 ;; the function of esac in shell script must represent $0 by the function name at the beginning of the program, and the subsequent parameter is also $1, $2... in the Loop while [condition] <= the state in the brackets is the Begin do <= do is the beginning of the loop! Program section done <= done is the end of the loop until [condition] do Program section done for var in con1 con2 con3... do program segment done for (initial value; limit value; execution step) do program segment done sh [-nvx] scripts. sh option parameter:-n: do not execute the script, only query syntax problems;-v: before executing scloud, output the content of scripts to the screen;-x: displays the script content on the screen. this is a useful parameter! You can use sh-x script. sh to debug the program.
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.