A shell is a command interpreter, he is the outermost layer of the operating system, is responsible for a user interacts with the system kernel, the command entered by the user to turn a system, then the result of the input, output feedback to the users of the system
Popular terms shell is put Unix/Linux
under the command into a file set to perform, it is not only a connected user and the Linux kernel programs, but also a management scripting language Linux command interpreter, it is the use of shell functions written a program, statements in the shell document and the result is fed back to the user, the shell provides arrays, loops, and logic condition judgment
We entered the command computer is not set up anything else, it requires a program to translate into binary own recognition, while the results back to us
Classification of programming languages
Programming language
Interpreted language
Language Category
1. 书写脚本
cat /server/scripts/shell.sh #!/bin/bash ----> 指定脚本默认使用的命令解释器 第一行 echo "hello word" #执行结果 [root@m01 /server/scripts]# sh shell.sh hello word
标注:
- 语法正确,文件有+x执行权限
- 以 # 开头,整行注释不执行
- 文件以
- source 或 . 替你在当前环境中 执行1次脚本 ,source 一般用来实现include 功能 或配置环境变量 别名后生效. /etc/init.d/functions
-
-
中间不能有空格,可以使用下划线
( _ )
。 -
不能使用标点符号。
-
不能使用bash里的关键字( 可用help帮助 )
-
等号 = 用于为变量分配值,等号两边不能有空格
-
变量存储的数据类型是整数类型和字符串类型
-
在赋值时建议用引号括起来。因为如果字符串中存在空格符号,需要使用单引号或双引号。
-
要对变量进行调用,在变量前加
$
变量的分类:
-
-
环境变量:主要保存和系统操作环境相关的数据。
-
位置参数变量:主要是用来向脚本当中传递参数或数据,变量名不能自定义,变量作用是固定的。
-
局部变量 是 shell 程序内部定义的,其作用仅限于定义它的程序,对其他程序不可见。包括:用户自定义变量、位置变量和预定义变量。
全局变量
含义 | |
---|---|
PATH | 指定命令的搜索路径 |
HOME | 指定用户的主工作目录(即用户登录系统时,默认路径) |
HISTSIZE | 指保存历史命令记录的条数 |
LOGNAME | 指当前用户的登录名 |
HOSTNAME | 指主机的名称,程序如果要用到主机名,通常从这个环境取得 |
SHELL | 指当前用户时那种Shell |
LANG/LAGUGE | 和语言相关的环境变量,使用多种语言的用户可以修改此环境变量。/etc/sysconfig/i8n |
指当前用户的邮件存放目录 | |
PS1 | 命令基本提示符,root用户是#,普通用户是$ |
PS2 | 附属提示符,默认是 ">" |
UID | 记录用户的UID信息 |
HISTCONTROL |