Shell scripting language Usage

Source: Internet
Author: User
Tags case statement switch case

Shell program run:

1./xx.sh. Running the shell this way requires the shell program to have executable permissions. chmod a+x xx.sh to add executable permissions.

2, Source xx.sh.

3. Bash Xx.sh,bash is a script interpreter, which is essentially an executable program. This execution is equivalent to executing a bash program and then passing xx.sh as argv[1] to him.

Typical applications for if
Determine if the file exists. (-F), note [] There are spaces inside and out, you cannot omit it.
Determine if the directory exists (-D)
Determine if the strings are equal ("str1" = "str2"), and note that you use an equal sign instead of two
Determine if the number is equal (-EQ), greater than (-GT), less than (-LT), greater than or equal to (-ge), less than or equal to (-le) recall the abbreviation that was used to determine the condition of arm assembler when it was executed in arm bare metal. (EQ is equal,gt is greater than,lt is less than,ge is greater or equal,le is less or equal)
Determines whether a string is empty (-Z) Note-Z is not valid if the variable itself is undefined (that is, Z does not define not equal to null).

Case statement
(1) The case statement in the shell acts as a switch case statement in C, with a slightly different format
(2) The case statement in the shell is inherently free of break and does not require a break, unlike the switch case in the C language. The case in the shell defaults to which of the matches on which one executes, and does not say that the other case is executed after execution (as if the case language in the shell defaults to a break).

the shell program itself can also be called Shishun. $ #表示调用该shell时传参的个数 ($ #计数时只考虑真正的参数个数). $, $, $2 Then each parameter of the argument is represented in turn.

When a case statement is embedded in a while loop, the break in a scenario jumps out of the outer while loop and is not used to jump out of the case statement.

The value of the $# built-in variable in the shell is not immutable, but can be changed and changed by the shift instruction. The shift instruction is a bit like the left-shift operator in C, which shifts the arguments we gave to the shell program to the left, and the original $ $ #少了1个 into the new $ $.

Shell scripting language Usage

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.