1. 什么是Shell Shell 是命令解释器,位于底层硬件( hardware )、系统内核( kernel )上层,是软件应用程序和系统内核沟通桥梁。Shell 输入用户指令至系统核心并将执行结果展示给用户,展示介质一般是屏幕。Shell中文可以理解为外壳。
  2. 什么是 Shell 脚本 Shell 脚本一般是文本文件,内部集成命令、语句块和循环等内容,通过 Shell 解释器执行。通用是.sh后缀。

Shell 脚本语言是弱类型语言,变量名称无需指定数据类型,Linux 系统下主要分为Bourne Shell 和 C Shell两种。Bourne Shell 包括 sh 和bash等,C Shell 包括 csh 和 tcsh 等。

本文假设用户已经完成安装 CentOS7.6,推荐个人用户使用 XShell 个人版,本文大部分命令在该软件下执行并显示,您还可以使用Putty等软件。系统和软件安装本文不涉及。

下文开始演示 shell 命令。编写环境如下

#Shell 查看系统信息方法1
[root@promote ~]# cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)
#Shell 查看系统信息方法2
#安装系统信息查看软件redhat-lsb
[root@promote ~]# yum install redhat-lsb -y
[root@promote ~]# lsb_release -a
LSB Version:	:core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:	CentOS
Description:	CentOS Linux release 7.6.1810 (Core)
Release:	7.6.1810
Codename:	Core

通过 Shell 脚本指令 cat 可以查看系统信息文件 /etc/redhat-release 显示当前系统为 CentOS Linux release 7.6.1810 (Core) 。后一个命令输出结果更为详细。

其他脚本语言还包括 PHP、Perl、JavaScript、Python 等,不在本文介绍范围内,不再加以详细介绍。Python 近几年很流行,可以在掌握 Shell 以后加以学习提升。

查看系统默认 shell 编辑器和全部解释器。

#系统默认shell 解释器
[root@promote ~]# echo $SHELL
/bin/bash
[root@promote ~]#
#系统shell 解释器
[root@promote ~]# cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
[root@promote ~]#
[root@promote ~]#

下一讲将演示创建 Shell 脚本文件。

03-31 15:58