FAQs about Shell on Linux

Source: Internet
Author: User
FAQ about Shell on Linux-general Linux technology-Linux technology and application information. For details, refer to the following section. Why use Shell programming?
Simple and quick, with wide applicability

What is Shell?
Shell is an interface between a user and a Linux system. You can use it to input commands for the operating system to execute.

What are the object descriptors 0, 1 and 2?
In Shell, 0 indicates the standard input, 1 indicates the standard output, and 2 indicates the standard error output.

> What is the role of a symbol?
When adding a file after the file, use >>, for example, ps >>> output.txt. the result of this sample will be at the end of the output.txt file, instead of the original content in the file.

In Shell commands, what is the meaning of common 2> & 1?
In Shell,> the symbol is often used to indicate the redirected output. The previous available file descriptor indicates the redirected output. The default value is 1 (standard output). If it is a redirected standard error output, 2> is used, and if it is & 1, the standard error output is redirected to the same position as the standard output.

What is the role of/dev/null?
If you want to discard the output result in the Shell command, you can directly drop it into the Linux garbage bin./dev/null is such a garbage bin. Example: kill-l 214>/dev/null

How to redirect input?
Which of the following statements is used to redirect input in shell? <符号,例如:more < ex.txt

Why MPs queue? How to Use pipelines?
In Shell, pipelines (pipe) are powerful and can be used to link commands to implement pipeline operations. The pipeline name is very vivid. It is the connection channel between commands. When using pipelines, you can connect the output of the previous command with the input of the next command. The symbol "|" is used ". Example: ps | sort | grep-v init | more

Wildcards in Shell
Shell wildcard functions are also quite powerful, mainly including the following categories:
1) *: match any character
2 )? : Match a single character
3) [set]: Match characters in the Set
4) [^ set]: Match characters not in the Set
5) {}: match the content in {}

Role''
In Shell, a ''symbol indicates that the content contained in the symbol is executed as a Shell command. Note the difference between it and common quotation marks. Example: more 'grep-l POSIX *'

Shell script writing
Note the following basic points for writing Shell scripts:
1) The first line starts with a comment. In fact, this is a special comment in the line ,#! It indicates the programs that execute the script, such :#! /Bin/bash indicates that the script is interpreted and executed by the/bin/bash program.

2) The last line ends with the exit command to ensure that the script can exit normally.

Grant execution permission to Shell scripts
The edited Shell script cannot be run directly. to run it in/shellfile mode, you need to grant the execution permission to the script. The common practice is chmod + x shellfile. You can also grant permissions to the specified user according to different permission requirements, for example: chmod 766 shellfile (another format: chmod o + x shellfile), The shellfile can be directly executed only by its owner user (owner.
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.