Shell Common Sense

Source: Internet
Author: User

  

 1 #!/bin/bash 2: <<! 3 #使用变量 4 Your_name= "QINJX" 5 echo $your _name 6 echo ${your_name} 7 #只卖变量 8 myurl= "HT tp://www.w3cschool.cc "9 readonly myurl myurl=" http://www.runoob.com "one #删除变量 unset Variab                                  Le_name #数据类型: Numbers and strings #定义字符串 str1= ' This is a string ' #单引号里的任何字符都会原样输出, the variable in the string is not valid for str2= "Hello, I know your is \" $str 1\ "! \ n "#双引号里可以有变量和转义字符 #读取字符串长度 string=" ABCD "Echo ${#string} # Output 4 #分割提取子字符串 string= "Runoob is a great site" "Echo ${stri                 Ng:1:4} # Output Unoo, 4 characters starting from the 2nd character of the string: #查找子字符串 string= "Runoob is a great company" 26 echo ' expr index ' $string ' is ' # output 8 27! : <<! #数组 #定义数组 array_name= (value0 value1 value2 value3) #或者 array_name= (VALUE0 35                 Value1 value2 Notoginseng value3 38) 39                         #单独定义各数组变量 Rray_name[0]=value0 array_name[1]=value1 #读取数组 43                 Valuen=${array_name[n]} #读取单个数组44 echo ${array_name[@]} #读取多个数组 45                         #数组的长度 46 # Gets the number of array elements length=${#array_name [@]} 48                         # or length=${#array_name [*]} 50 # Gets the length of the array single element 51                 lengthn=${#array_name [n]} #基本运算 #加算 val= ' expr 2 + 2 ' 55 echo "Sum of two numbers: $val" #减算 "expr $a-$b ' \* #乖算 ' expr $a ' 6        0 #除算 61         ' Expr $b/$a ' #除余 "expr $b% $a ' a= #赋值 66 #相等 [$a = = $b] #返回布尔值 #不相等 [$a! = $b] #返回布尔值 70!         #if判断 a=10 b=20, if [$a! = $b] and echo "A not equal to B" 77  Fi 78 79 80

  

Shell Common Sense

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.