Shell for Linux Learning

Source: Internet
Author: User


What is Shell for Linux learning? Shell is an interface for user interaction with the kernel. It can be used as a command interpreter. After a user inputs a command, shell will explain it and then send it to the kernel for execution, after knowing what shell is, let me know which shell is used in linux. Isn't there more than one shell in linux? Of course, you can view the/etc/shells file to see which shells in the current system are similar to each other. You only need to know one of them. In most linux systems, the default shell is bash, so let's take a look at bash: 1. bash shell's built-in command: type. We can know whether it is an imperative built-in command or an external command through type. Type [-t] command-t: When the parameter t is added, the result is as follows: file: refers to the external command www.2cto.com alias: refers to the name builtin set for this imperative alias: indicates that the command is bash built-in command 2. Display and set echo of the variable in bash. unset you can use echo to display the variable, but when the variable is displayed, you must add "$" to get the PATH content echo $ PATH or echo $ {PATH}. How to set a variable? The following are some rules: the content of the variable and the variable is connected with a = sign. No space is allowed on both sides of the equal sign B, if a space is enclosed in single or double quotation marks, special characters in double quotation marks ("$") can be kept as original content, but single quotes cannot be d. If other commands are required to provide information in a single string of commands, you can use the 'command' or $ (command) e. Cancel a variable. Use unset 3. Check the environment variable. Use the env or export command to view all the variables in the system. set www.2cto.com 4. Read the variables from the keyboard. This knowledge point is used in many shell scripts.

5. declare the variable type declare [-iaxr] vara: array type I integer x global variable r read-only type

Have you seen the difference above? Next we will learn how to delete the very practical technical variable content and replace the content of the deleted variable. We mainly remember four symbols: #: Start from the left side of the variable content, the shortest character matching the content you want to delete #: The longest character matching the content you want to delete starting from the left of the content of the variable %: Starting from the right of the content of the variable, the shortest character % that matches the content you want to delete: starts from the left of the variable content, * of the longest character www.2cto.com that matches the content you want to delete indicates the replacement Syntax of 0 or multiple arbitrary characters: $ {var/old/new} // replace the previous $ {var // old/new} // replace all bash logon information changes: first use cat/etc/issue
What should you do if you want all users to obtain some information after logging on, such as announcements? Modify the environment configuration file of the/etc/motd file bash. The following two concepts are introduced: login shell and non-login shelllogin shell: the complete logon process is required when bash is obtained, it is called login shell, for example, from the tty1-tty6 login, you need to enter the user account and password, at this time the obtained bash become login-shellnon-login shell: when obtaining bash, I did not log on to www.2cto.com. For login shell to read back two configuration files/etc/profile at startup: This is the overall configuration of the system. You 'd better not change it ~ /. Bash_profile or ~ /. Bash_login or ~ /. Profile is a personal setting of users. You need to modify your own data and write it here. The login shell setting of the following three files will only read one of the above three minutes, the read order is as follows:/etc/profile and ~ /. Bash_profile is read in the login shell, so you need to write your preference settings to the above file, usually log out, can I directly read the configuration file without logging out? Yes. Use the source command to configure the file source ~ /. Bash_profile or .~ /. Bash_profile data stream redirection literally means to transmit data to other places. By default, we execute a command, regardless of whether it is correct or wrong, the results are all in reality on the console, so now we want to save it to a file and how to do it, please refer to the following: Example 1 sets the execution result to result.txt
Save the error information in the execution process to www.2cto.com in err. log.

A brief explanation of the above case: the standard input code is 0 to use <or <The standard output code is 1 to use> or> standard error output: the code is 2. Use 2> or 2> to indicate empty and write> to accumulate Example 2 and discard the error message. Only the correct information is displayed. find/home-name. bashrc 2>/dev/null
Example 3 store the correct information and error information in different information to find/home-name. bashrc> list_right 2> the list_error standard input is described in a simple way, that is, the data originally required by the keyboard is changed to the file content instead of the example 1. Use the cat command to create a file cat> catfiletesting www.2cto.com cat file test press Ctrl + d and then use cat catfile to view the content Example 2 Pipeline command pipeline command is "| ", the so-called pipeline is to use the result of one command as another command input Example 1

Author: yuanzeyao2008

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.