Shell programming------variables, assignments, and operations

Source: Internet
Author: User

1. Variable assignment:NAME=LBG equals sign cannot have spaces name= "Lebron James" variable values have spaces in double quotes Echo ${name} with ${} More insurance shopt-s-O Nou Nset setting "Declare and use first" 2. Cancel the variable:unset releasing memory for variables and functions 3. Position parameters:${N}: Input nth parameter ($ = script name) $#: number of input parameters [email protected]: input all parameters $!: The last parameter of the input $?: The return value of the previous command (used in the script to convict The execution state of the previous command, any return that is not 0 indicates an abnormal execution) 4. Arrays:Declare-a array= (' ladawn ' LBG ' LBJ ') 5. Read-only variables:Declare-r n=10 readonly n=10 6. Variables in the function:If you do not declare local, the variable in the function is also a global variable. If declared as local (local var=200), the scope of the variable is only within the function. 7. References:Double quotes: Weak references, special symbols ($, \, ') still resolve to special meanings. Single quote: Strong reference, all characters are literal meaning, no longer have special meaning. 8. Command replacement:a=$ (data) or a= ' data ' means that the output of the data command is taken out and assigned to a 9.BC Operation:Used for floating point calculation output.            Used by pipelines. Tatal=$ (echo "34/15" | BC) 9. Numerical Operation:Let "sum+=1" means sum = sum+1 let "j=sum%2" means j = sum% 2

Shell programming------variables, assignments, and operations

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.