[Linux] shell quick learning summary [TBD]

Source: Internet
Author: User

Shell version
SH: Bourne shell, the original Unix shell.
CSH: C shell.
Ksh: Korn shell.
Bash: Bourne again shell. Linux default shell.
Tcsh: C shell extension.
Pdksh: Ksh is not free. This is free.

Echo-n "Date and time is:"-N does not wrap.
Echo "Your name is: 'whoam'" ''interprets the strings as commands.

Shell script execution Method
Bash <XXX. sh: read and execute the command line from XXX. Sh.
Bash XXX. sh: it can contain parameters.
Chmod A + x XXX. sh: enables XXX. Sh to "execute" all users. Enter the Script Name and run it directly.

Special characters
Double quotation marks: Except $ USD, 'inverted quotation marks, \ backslash, and other common characters.
Single quotes: the characters in single quotes are considered as common characters.
Inverted quotation marks: the key under ESC in the upper left corner. The internal string is interpreted as a command. Shell executes the command first, and replaces the entire inverted quotation mark with the result.
Backslash: converts a special character into a common character, and prevents shell from interpreting the character following it as a special character.

I/O redirection
Input: <redirects the stdin of the command to a specified file and reads the content from the file as the input.
Output:> redirects the stdout command to a file and writes the execution result to the file. When multiple commands are executed to the same file, the preceding commands will be overwritten.
Output appending:>, appended to the end of the file, does not destroy the original file content.
Real-time file: <, composed of <", a pair of tokens and several inputs between them. Allows you to direct the input line of a shell program to a command .?????

Note: # Start to indicate comments. #! It indicates the absolute path of the shell. #! /Bin/CSH #! /Bin/bash
Pipe Line: several commands separated by |. Each Command has an independent process. The previous command output serves as the next input.

Command Execution Operator
Sequential execution: You can execute one or more commands separated by a comma (;). Failed execution does not affect subsequent execution.
Logic and: command 1 & command 2, command 1 successful, continue command 2. Otherwise, do not continue. If the execution is successful, 0 is returned. Otherwise, the value is not 0.
Logic or: command 1 | command 2, run 1, fail to execute 2; otherwise, 1 is successful, do not execute 2.

Variable
Variable names are case sensitive. If the value assigned to a variable contains spaces, tabs, or line breaks, double quotation marks are used. For the same variable, int and string can be stored at one time.
Access through the dollar sign, such as yourname = $ myname;

Internal Variable
$ # (Number of parameters passed to the program, excluding itself)
$? (Execution result of the last command)
$0 * (your own name)
$ * (String of all parameters passed to the program, excluding itself)

Environment Variable
Home:/home/Username
LOGNAME: the user's registration name, which is automatically set in Linux. It is the name of the system interaction with the user.
Mail: the user's system email path,/var/spool/mail/Username
Path: the list of directories from which Shell finds commands.
PS1: defines how a user's primary prompt is formed. For example, \ U @ \ H: \ W # Corresponds to wgsupport @ firebox :~ #. [\ U @ \ H \ W] \ $ corresponds to [Ryo @ t430-lap documents] $.
PWD: Path of the user's current working directory.
Shell: The current shell used by the user. It also points out the location where the user shell interpreter is placed.
Term: user terminal type.

Location parameters
When a shell script is called by someone else, you can pass in the parameter, the first $1, the second $2 until $9.
Set can be used to set or reset parameters.
If the parameter is greater than 9, shift left is used. Shift: move one, shift 4: Move Four.

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.