CentOS 7 Shell脚本编程第一讲 Shell知识入门

  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 ~]# 
#CentOS 7.6 Bash和sh实际为同一个文件
[root@promote ~]# which sh
/usr/bin/sh
[root@promote ~]# ls -al /usr/bin/sh
lrwxrwxrwx. 1 root root 4 2月  21 23:24 /usr/bin/sh -> bash
[root@promote ~]# which bash
/usr/bin/bash
[root@promote ~]# ls -al /usr/bin/bash
-rwxr-xr-x. 1 root root 964608 10月 31 01:07 /usr/bin/bash
[root@promote ~]# 


下一讲将详细演示如何创建 Shell 脚本文件。

 

转载于:https://my.oschina.net/u/1011130/blog/3030384

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值