Basic knowledge---understand the shell and various sh and update bash to a high-level bash5.0

                                  Basic knowledge---understand the shell and various sh and update bash to a high-level bash5.0

One, what is a shell? What is bash?

It is the kernel that manages the computer hardware. The user communicates with the kernel through the shell. In essence, the shell is a macro processor that can execute various commands. And bash (/bin/bash) is the default shell of Linux. In fact, in human terms, a shell is a shell, a bridge, and a road outside the kernel. It is essentially a piece of software, but this software does something unusual. It accepts user commands and then interprets and executes the commands to call the system kernel All kinds of resources, including all kinds of hardware resources, such as cpu, memory, memory management, etc. Of course, another meaning of the shell is a language, since it is a language, then there are some specifications. Programs like /usr/bin/bash are interpreters that implement the shell language.

I believe that after reading the above content, many students may be even more confused, it doesn't matter, this world is so cruel. The main reason is that the definition of shell is very broad, but there are two keywords, command interpreter (like a compiler?), language, remembering these two keywords is easy to understand.

The broad and specific definition of shell, as long as it is an interface between humans and computers, it can be called Shell. Command line: bash, sh, csh, ksh, ash, zsh, graphical: KDE, GNOME, CDE, XFCE​​​​​​​ After your "Shell" is recognized, it is translated into an instruction to call the program. After the execution is successful, the result can be translated into voice and then returned to you. For example, you must be familiar with "Little Ai", something like "Hi Siri" can also be called a shell. The situation of windows is slightly more complicated. The kernel of the Windows 9X series is DOS, the graphical shell is called Windows Explorer, and the command line shell is called command. Starting from Windows XP, the kernel of Windows is called Windows NT (Windows New Technology), the graphical shell is called Windows Explorer, the command line shell has command, cmd.exe, and Windows PowerShell is also introduced later.

In fact, whether it is a command-line shell or a graphical shell, or a voice-activated shell dressed in artificial intelligence, it is possible to access a file in the operating system that has a certain function and can handle specific affairs (binary file ---- this Class files are often called tools), or files containing certain content (text files), which are usually accessed through file names (of course there are exceptions, such as Linux’s alias command, such as accessing source files through link files), so usually files The name becomes the command. Calling and executing interpreted commands is the most fundamental function of the shell.

Various Linux distributions now basically use the bash shell uniformly, and ash, csh, ksh, and zsh are not commonly used or universal shells.

a, sh and bash

First, let's look at the version information of bash in use.

[root@centos9 ~]# bash --version
GNU bash, version 4.2.46(2)-release (x86_64-redhat-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

 What is the relationship between sh and bash?

[root@centos9 ~]# ls -alh /bin/sh
lrwxrwxrwx 1 root root 4 Sep  6 11:05 /bin/sh -> bash
[root@centos9 ~]# ls -alh /bin/bash
-rwxr-xr-x 1 root root 942K Apr  1  2020 /bin/bash

As you can see, sh is the link file of bash, and the size of bash is 942k, which is close to one megabyte. 

Then, my operating system is centos7 version, the default operating system is bash, the version is 4.2.46. The last two sentences say that this is a free and free software, you can edit or re-develop it without additional legal restrictions.

Sometimes, the default bash version that comes with the operating system may not meet our security expectations, because the old version may have various security bugs, and I want to upgrade it to 5.0 (released in 2019). May I? Of course, this is the arrangement.

http://ftp.gnu.org/gnu/bash/bash-5.0.tar.gz  is the download address. After the download is complete, upload it to the server, decompress the quality three times, and understand everything. Any software that needs to be compiled, gcc-c++ is indispensable, this must be kept in mind .

yum install gcc-c++ -y

cd to the unzipped directory, ./configure && make && make install

[root@centos9 bash-5.0]# pwd
/root/bash-5.0
[root@centos9 bash-5.0]# ./configure && make && make install

Back up the original bash main file and link the new bash main file to the original location 

[root@centos9 bash-5.0]# mv /bin/bash /bin/bash.bak
[root@centos9 bash-5.0]# ln -s /usr/local/bin/bash /bin/bash

 Check the version of bash to verify that the upgrade is correct:

[root@centos9 bash-5.0]# bash --version
GNU bash, version 5.0.0(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Note: Although the bash upgrade was successful, csh is completely unavailable. The specific reason is not clear. To be investigated .

b, csh and tcsh

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

[root@centos11 ~]# ls -al /bin/csh
lrwxrwxrwx 1 root root 4 Sep 26 11:39 /bin/csh -> tcsh
[root@centos11 ~]# ls -al /bin/tcsh
-rwxr-xr-x 1 root root 404640 Apr  1  2020 /bin/tcsh
[root@centos11 ~]# ls -alh /bin/tcsh
-rwxr-xr-x 1 root root 396K Apr  1  2020 /bin/tcsh

The above shows that csh is a link file of tcsh. These files are under the system environment variables. The file size of tcsh is 396k, which is much smaller than bash. Of course, it has fewer functions.

c, Korn Shell, also known as ksh

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, David Korn, AT&T's bell laboratory, developed the Korn shell. ksh combines all the interactive features of the C shell and incorporates the syntax of the Bourne shell. Therefore, Korn shell is very popular among users. It also adds functions such as mathematical calculation, coprocess, and inline editing. Korn Shell is an interactive command interpreter and command programming language. It conforms to POSIX-an international standard for operating systems. POSIX is not an operating system, but a standard that aims at the portability of applications-in source code One level spans multiple platforms.

d,Bourne Shell

The first important standard Unix Shell was introduced in V7 Unix (AT&T 7th Edition) at the end of 1979, and based on its founding Ministry of Science and Technology basic condition platform "National Meteorological Network Computing Application Node Construction" (2004DKA50730) funder Stephen Bourne Named. The Bourne shell is an interchangeable command interpreter and command programming language. The Bourne shell can be run as a login shell or a subshell of the login shell. Only the login command can call the Bourne shell as a login shell. At this point, the shell first reads the /etc/profile file and the $HOME/.profile file. The /etc/profile file customizes the environment for all users, and the $HOME/.profile file customizes the environment for this user. Finally, the shell will wait to read your input.

e,POSIX Shell

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

 

 

 

The default shell used by the major operating systems is:

Under AIX is Korn Shell.

Solaris defaults to the Bourne shell.

FreeBSD defaults to the C shell

HP-UX defaults to the POSIX shell.

Linux是Bourne Again shell

Undoubtedly, the last one, that is, bash is the most powerful shell, and it is also the most used and most commonly used shell. If the Shell function successfully executes the file to be executed, it will return the task ID of the program. The task ID is a unique value used to indicate the running program. If the Shell function cannot open the named program, an error will be generated. ​​​​​​​(The origin of pid, I haven't seen the same pid at any time in any operating system).

 

To sum up: bash upgrade will destroy csh and tcsh. Therefore, if the operating system you are using requires csh to work, please do not upgrade blindly .

The command to switch the shell is: chsh, an example is as follows:

[root@centos11 ~]# chsh
Changing shell for root.
New shell [/bin/bash]: /bin/tcsh
Shell changed.
[root@centos11 ~]# tcsh
[root@centos11 ~]# echo $SHELL
/bin/bash

Changing the shell to tcsh will take effect after restarting the system. The effect after restarting:

[root@centos11 ~]# echo $SHELL
/bin/tcsh
[root@centos11 ~]# 
[root@centos11 ~]# cat /etc/passwd | grep root
root:x:0:0:root:/root:/bin/tcsh
operator:x:11:0:operator:/root:/sbin/nologin

As you can see, the shell interpreter of the passwd file has been automatically changed to tcsh.

 

 

Guess you like

Origin blog.csdn.net/alwaysbefine/article/details/113791985