(vii) Shell programming learning

Source: Internet
Author: User

1. Shell program Exercise: Create a Dir folder and create a cd.c file in the Dir folder

First VIM hello.sh

2. Variable definitions and references in the shell

(1) Definition and initialization of variables. A shell is a weakly typed language (a variable in a language is a strongly typed language if it has a definite type), a variable with no explicit type is a weakly typed language, and a different C language. Defining variables in shell programming does not require a type, nor is there a concept of type.
(2) Variable definition can be initialized, use = to initialize the assignment value. The value assigned in the SHELL = There cannot be spaces on either side.
Note: The shell is very concerned about the syntax, very strict. A lot of places have to be empty or must have, and can not arbitrarily have no spaces.
(3) Variable assignment, the variable can be assigned again after the value, the new assignment will overwrite the old assignment. The shell does not deliberately distinguish between the definition and assignment of variables, anyway, each variable is a symbol, the value of this symbol is the last value assigned to him.
(4) Variable reference. A variable referenced in the shell must use the $ symbol, and the $ symbol is the variable dereference symbol.
Note: The $ symbol is followed by a string, and the string is parsed as a variable. If the string itself is undefined, execution does not give an error, but instead resolves the variable to null. In other words, a variable that is not defined in the shell is actually a variable that is defined and assigned an empty value.
Note: Variable references can be $var or ${var}. The difference between the two is that in some cases you can only use ${var} and not simply $var

3. The difference between a shell without references, single quotes, and double quotes

(1) using strings in the shell can be used without double quotes. You can also have a space, but the flaw is not output "or other escape characters.
(2) The shell can also use single quotation marks to represent strings, which are also used directly, and cannot output escape characters.

(3) Single quotes: completely literal substitution (cannot contain single quotation marks itself)
(4) in double quotes:
$ plus variable name to take the value of the variable
Anti-quotation marks still indicate command substitution
\$ $ literal Output $ symbol
The literal value of \ ' representation '
The literal value of \ "represents"
\ \ denotes the literal value of \
In addition to the above, there is no special meaning in front of other characters, only the literal value.

(vii) Shell programming learning

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.