Shell Getting Started exercise

Source: Internet
Author: User
Tags define local logical operators

* * Define local variables, local variables will expire when exiting the shell client * *

* * Single quote: Output AS-is * *

* * Double quotes: If there are variables, the variables will be output * *

* * No quotation marks: Output variable * *

You can pass parameters to the script when the script is called, using the $ $ ... in the script. Accept parameters that are passed and need to be enclosed in curly braces when the argument exceeds 9 ${10}

Special Invocation Parameters:

    $0:返回Shell文件名称    $$:当前脚本的PID    $#:传递的所有参数 [email protected]:程序中的所有参数,这是将参数传递给其他程序的最佳方式。 $! :执行的上一个命令的PID $?:上一次指令的返回值 $_:此命令前面的最后一个参数 $* :获取所有的参数

* * sh scripts that start with a command will disappear when the script ends, and other scripts cannot access their internal properties.

When source you start a script with a command, its properties are not invalidated when the script ends, and other scripts can access it.

Validated, used ./ can also execute scripts

Use unset to cancel a variable, which includes environment variables and local variables * *

Defining arrays array=(value1 value2 value3) array_name[0]=value0

Reading an array${array_name[index]}

Get all the elements in an array${my_array[@]}

Gets the length of the array${#my_array[*]}

Process Control
If

If no statement is executed in the Else statement, it cannot be written

If conditionthen command1 command2 ... CommandN fi------------------if conditionthen command1 command2 ... commandnElse commandfi------------if Condition1then command1elif condition2 Then  command2else commandnfi           
For
for var in item1 item2 ... itemNdo    command1    command2 ... commandNdone
While
while conditiondo    commanddone
Until

Similar to the Do-while cycle, at the Last Judgment condition, at least once

until conditiondo    commanddone
Case

Case Value in

Mode 1) Command1 Command2 ... CommandN;;

Mode 2) Command1 Command2 ... CommandN;; Esac

Function
demoFun(){   // 定义      echo "这是我的第一个 shell 函数!"}echo "-----函数开始执行-----"demoFun // 调用,如果需要传递参数直接在后面跟就好 demoFun 1 2 3echo "-----函数执行完毕-----"

Operator
    • Expr is an expression evaluation tool that uses it to perform evaluation operations on expressions.

    • expr 2 + 2To use the method, you need to be aware of 1. There is a space between the expression and the operator 2. Need to use ' ' cause

Relational operators

How to use

 if [ $a  -lt -a  $b -GT 15] then echo  "  $a less than 100 and  $b greater than 15: Returns True "else" Span class= "hljs-built_in" >echo  " $a less than 100 and  $b greater than 15: returns false" fi                   

logical Operators



Shell Getting Started exercise

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.