Shell 13: What is shell?

Source: Internet
Author: User

Before introducing what shell is, let's review the relationship between users and computer systems. We know that computer operations cannot leave hardware, but users cannot directly drive hardware, hardware drivers can only be controlled through a software called "Operating System". In fact, we talk about FreeBSD, NetBSD, OpenBSD, and Linux every day, strictly speaking, it is just an operating system, which is called "core )". However, from the user's point of view, the user cannot directly operate the kernel, but through the "shell" program of the kernel, that is, the so-called shell
To communicate with the kernel. From a technical point of view, shell is an interface between the user and the system. It allows the user to use the system through command line to complete the work. Therefore, the simplest definition of shell is --- Command Interpreter ):
* Translate users' commands to the core for processing,
* At the same time, the core processing result is translated to the user.

Every time we log on to the system (LOGIN), we get an interactive shell called login shell or primary shell. From the process perspective, the commands we run in shell are all sub-processes produced by shell. This phenomenon can be called fork for the time being. For shell scripts, the commands in the script are executed by another non-interactive subshell. That is, the process where primary shell generates sub shell, sub shell
The process that generates all commands in the script.

Two shells can be used in FreeBSD's basic system: SH and CSH. The two basic shells have different styles. Different users often choose between them based on their preferences. Of course, there are currently better Shell programs available for users to choose from. These subsequent shells are developed based on the sh or CSH style. Therefore, in shell, there are also two styles. You need to select one based on your usage habits.
By default, FreeBSD supports SH, CSH, and Tsch, as shown in/etc/shells.
Command Prompt to add:
If the shell is sh, the prompt is "$". If the shell is CSH, the prompt is "%". Note that if the shell is a root user, the prompt is "#".

SH and CSH have the following different branches:
Bourne shell:
Burne shell (SH)
Burne again shell (BASH)
Korn shell (Ksh)
POSIX shell (SH) C shell:
C shell (CSH)
Tenex/tops C shell (tcsh)
Quote:

The original Unix shell of the Bourne shell was written by Stephen R. Bourne at the at&t Bell lab in New Jersey in the middle of 1970s. This is the Bourne shell. Bourne shell is an exchange-type command interpreter and command programming language. The Bourne shell can run as a sub-shell (subshell) of login shell or login shell ). Only the LOGIN command can call the Bourne shell as a login shell. In this case, shell first reads the/etc/profile file and $ home/. ProFile. The/etc/profile file customizes the environment for all users
Environment, $ home/. ProThe file is a customized environment for the user. Finally, shell will wait to read your input.

C shell Bill Joy developed C shell at the University of California in Berkeley in the early 1980s S. It is mainly used to make it easier for users to use interactive functions, and converts the ALGOL-style syntax structure into the C language style. It provides functions such as command history, alias, file name replacement, and job control.

For a long time, there were only two types of shells for people to choose from. The Bourne shell was used for programming and the C shell was used for interaction. To change this situation, at&t's Bell lab David Korn developed the Korn shell. Ksh combines all the interactive features of C shell and incorporates the Bourne shell syntax. Therefore, the Korn shell is widely used by users. It also provides functions such as mathematical computing, coprocess, and inline editing. Korn shell is an interactive command interpreter and command programming language. It complies with POSIX-an international standard for operating systems. POSIX is not an operating system, but a goal of application portability.
The standard-crossing multiple platforms at the source program level.

Bash is part of the GNU program and used to replace the Bourne shell. It is used in GNU-based systems such as Linux. Most Linux (Red Hat, slackware, Caldera) use Bash as the default shell, and bash is actually called when SH is run.

POSIX shell is a variant of the Korn shell. Currently, the largest seller of POSIX shell is Hewlett-Packard. In HP-UX 11.0, POSIX shell is/bin/sh, while bsh is/usr/old/bin/sh.

The default shell in main operating systems: Korn shell in Aix. Solaris and FreeBSD are the Bourne shell by default in HP-UX. POSIX shell. Linux is the Bourne again shell by default.

Enter the echo $ shell command to view the shell you are using. You can also view the shell at the prompt. If the shell is sh, the prompt is "$". If the shell is CSH, it is "%". Note that if it is a root user, the prompt is "#".

For administrators, to set the basic environment for users who use different shells, they must understand these two shell settings.
When logging on to the system, SH will first execute the/etc/profile file to set the most basic environment for each user, and CSH will use/etc/CSH. cshrc, CSH. login and CSH. logout is used as the system CSH resource file.

After the system-level logon file is executed, each user's shell searches for the user's personal resource file in the user's home directory: Sh uses. ProFile file. CSH uses the. login and. cshrc files. These resource files all use the corresponding shell language,/etc/profile and. Pro under the personal directoryFile uses the sh-style control language, and/etc/cshrc and. login and. cshrc in the personal directory use the CSH-style control language.

The system administrator can modify these resource files to provide users with the most convenient environment. Of course, the system administrator does not need to directly modify the resource files in the personal home directory. These files should be managed by the user. However, the system administrator can generate default resource files for the user when generating an account, to ease the trouble of setting resource files. By default, the adduser command uses files under/usr/share/skel to provide users with default settings for various resource files. In addition to the shell resource files, you can also add resource files of other applications. These resource files are hidden files starting with a vertex. To make it clear, a conversion method is used in the skel directory, such as Dot. Pro.File
As. ProFile template.

CODE:

# Ls/usr/share/skel
Dot. cshrc dot. login_conf dot. mailrc dot. rhosts
Dot. login dot. mail_aliases dot. ProFile dot. SHRC

The default configuration file set for the user in/usr/share/skel does not affect the user after the user is generated. Therefore, modifications to system logon files are more effective and direct. For sh-style users, you can change the/etc/profile file. For CSH, change the/etc/CSH. cshrc file. In these files, you can change the environment variables used by the shell to change the shell behavior mode, or execute a series of automatic operations to complete some tasks that need to be automatically executed when users log on.

Common environment variables:
Editor sets a commonly used editor for users. Many programs view this variable to start a specific Editor, which can be changed according to the system conditions.
The name of the home directory of the home user. This variable is set by the login program and does not need to be changed.
Displayx uses this environment variable to identify the specific display location, in the format of "computer name: X Server serial number. display serial number, for example, xt1: 0.0, which does not need to be defined in the resource file
The language used by the Lang System for system localization. The default value is "C". For specific settings, see the/usr/share/locale directory, where different languages are defined, you can set it to zh_cn.euc so that some software uses Chinese characters.
The location of the Mail User's mail file does not need to be changed.
The path is a series of paths separated by colons. The system uses it to find specific executable programs. Therefore, this variable is very important and can be changed based on the actual situation. For security reasons, do not use the current directory as the search path for the execution program, especially for root users. In this way, you need to add a path to start the program in the current directory, for example, start the. Out Program in the current directory, and enter "./A. Out"
.
Manpath is a series of paths separated by colons. The system uses it to find the online manual of a specific command. The setting method is the same as that of path.
The shell in the PS1 sh style uses the value of this variable as the prompt. The default value is "$" (root is "#"). The more modern sh enhances the flexibility of the prompt. You can add the current directory, user name, machine name, and command serial number to the prompt.
The PS2 sh shell uses the value of this variable as a subsequent prompt, prompting that the command has not been fully entered. The default value is ">;"
The type of term terminal is very important for programs that require full screen operations. Sometimes you need to adjust the settings as needed.
TZ time zone settings. The specific time zone information is located in the/usr/share/zoneinfo directory and must be set to the standard value suitable for the local time zone.

You can set your shell as a special application to restrict special users. For example, you can change the user's shell to/bin/true or another program that exits immediately, instead of giving the user the right to use the terminal. To ensure security, the User Shell should be a binary program without any vulnerability. It is best not to use the explanatory language script as the login shell. Because the Shell programs recognized by the system are listed in the/etc/shells file, the shell of special users is set as special applications, but these
If the application is not included in the shells file, the user will be differentiated by some applications from common users and thus refuse to provide services. For example, the FTP server program ftpd checks whether the user's shell is a standard shell to identify whether the user is a common user or a user for a specific purpose.

For example, when compiling and installing MySQL through source code, you need to first create a MySQL user, which we do not want to log on to the system, so set its shell to/nonexistent:

PW groupadd MySQL
PW useradd mysql-G mysql-S/nonexistent
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.