整理内容
parent
c40997633b
commit
6a9206b154
72
README.md
72
README.md
|
@ -1,16 +1,6 @@
|
|||
# 操作系统指南
|
||||
# Linux 教程
|
||||
|
||||
> 作为研发工程师,谁还没干过点运维的活?:joy:
|
||||
>
|
||||
> 搞运维,怎么着也得懂点操作系统相关。
|
||||
>
|
||||
> 本项目,就是本人在日常学习工作中,对于操作系统、运维部署等相关知识的整理。
|
||||
|
||||
## :memo: 知识点
|
||||
|
||||
### [Linux](docs/linux)
|
||||
|
||||
#### [Linux 命令](docs/linux/cli)
|
||||
## [Linux 命令](docs/linux/cli)
|
||||
|
||||
> 根据应用场景,将常见 Linux 命令分门别类的一一介绍。
|
||||
>
|
||||
|
@ -26,57 +16,47 @@
|
|||
8. [Linux 硬件管理](docs/linux/cli/08.Linux硬件管理.md) - 关键词:`df`, `du`, `top`, `free`, `iotop`
|
||||
9. [Linux 软件管理](docs/linux/cli/09.Linux软件管理.md) - 关键词:`rpm`, `yum`, `apt-get`
|
||||
|
||||
#### [Linux 工具](docs/linux/tool)
|
||||
## [Linux 工具](docs/linux/tool)
|
||||
|
||||
- [Git](docs/linux/tool/git)
|
||||
- [Vim](docs/linux/tool/vim.md)
|
||||
|
||||
#### [Linux 脚本编程](docs/linux/scripts)
|
||||
## [Linux 脚本](docs/linux/scripts)
|
||||
|
||||
- [一篇文章让你彻底掌握 shell 语言](docs/linux/scripts/shell.md)
|
||||
- [Python](docs/linux/scripts/python.md)
|
||||
- [一篇文章让你彻底掌握 python 语言](docs/linux/scripts/python.md)
|
||||
|
||||
#### [Linux 运维](docs/linux/ops)
|
||||
## [Linux 运维](docs/linux/ops)
|
||||
|
||||
#### Linux 服务器运维
|
||||
### Linux 服务器运维
|
||||
|
||||
- [Linux 典型运维应用](docs/linux/ops/linux典型运维应用.md)
|
||||
- [samba 使用详解](docs/linux/ops/samba使用详解.md)
|
||||
|
||||
#### 应用、服务、工具运维和调优
|
||||
### 软件安装、配置、调优
|
||||
|
||||
> :bulb: **说明**
|
||||
>
|
||||
> 这里总结了一些常用开发软件的安装、配置、使用指南。
|
||||
>
|
||||
> 此外,提供了一键安装、配置脚本,:point_right: [**软件安装配置脚本**](https://github.com/dunwu/os-tutorial/tree/master/codes/linux/ops/soft)。
|
||||
> 此外,提供了一键安装、配置脚本,:point_right: [**软件安装配置脚本**](https://github.com/dunwu/linux-tutorial/tree/master/codes/linux/ops/soft)。
|
||||
>
|
||||
> [环境部署工具](https://github.com/dunwu/os-tutorial/tree/master/codes/deploy) :适合开发、运维人员,在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。
|
||||
> [环境部署工具](https://github.com/dunwu/linux-tutorial/tree/master/codes/deploy) :适合开发、运维人员,在 [CentOS](https://www.centos.org/) 机器上安装常用命令工具或开发软件。
|
||||
|
||||
- 研发环境
|
||||
- [JDK](docs/linux/ops/soft/jdk.md)
|
||||
- [Maven、Nexus](https://github.com/dunwu/javastack/tree/master/docs/javatool/build/maven)
|
||||
- [Nginx](https://github.com/dunwu/nginx-tutorial)
|
||||
- [Nodejs](docs/linux/ops/soft/nodejs.md)
|
||||
- [Tomcat](docs/linux/ops/soft/tomcat.md)
|
||||
- [Zookeeper](docs/linux/ops/soft/zookeeper.md)
|
||||
- 研发工具
|
||||
- [Jenkins](docs/linux/ops/soft/jenkins.md) - 持续集成和持续交付平台。
|
||||
- [Elastic](docs/linux/ops/soft/elastic) - 常被称为 `ELK` ,是 Java 世界最流行的分布式日志解决方案 。 `ELK` 是 Elastic 公司旗下三款产品 [ElasticSearch](https://www.elastic.co/products/elasticsearch) 、[Logstash](https://www.elastic.co/products/logstash) 、[Kibana](https://www.elastic.co/products/kibana) 的首字母组合。
|
||||
- 版本控制
|
||||
- Gitlab - Git 代码管理平台
|
||||
- [Svn](docs/linux/ops/soft/svn.md) - Svn 是 Subversion 的简称,是一个开放源代码的版本控制系统,它采用了分支管理系统。
|
||||
- 消息中间件
|
||||
- [Kafka](docs/linux/ops/soft/kafka.md) - 应该是 Java 世界最流行的消息中间件了吧。
|
||||
- [RocketMQ](docs/linux/ops/soft/rocketmq.md) - 阿里巴巴开源的消息中间件。
|
||||
- 数据库
|
||||
- [Mysql](https://github.com/dunwu/database/blob/master/docs/mysql/install-mysql.md) - 关系型数据库
|
||||
- [PostgreSQL](https://github.com/dunwu/database/blob/master/docs/postgresql.md#安装) - 关系型数据库
|
||||
- [Mongodb](https://github.com/dunwu/database/blob/master/docs/mongodb/install-mongodb.md) - Nosql
|
||||
- [Redis](https://github.com/dunwu/database/blob/master/docs/redis/install-redis.md) - Nosql
|
||||
| 软件 | 说明 |
|
||||
| ----------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| [JDK 安装](docs/linux/ops/soft/jdk.md) | 不解释 |
|
||||
| [Elastic 安装](docs/linux/ops/soft/elastic) | 常被称为 ELK ,是 Java 世界最流行的分布式日志解决方案 。 ELK 是 Elastic 公司旗下三款产品 ElasticSearch 、Logstash 、Kibana 的首字母组合。 |
|
||||
| Gitlab | Git 代码管理平台 |
|
||||
| [Jenkins 安装](docs/linux/ops/soft/jenkins.md) | 持续集成和持续交付平台。 |
|
||||
| [Kafka 安装](docs/linux/ops/soft/kafka.md) | 应该是 Java 世界最流行的消息中间件了吧。 |
|
||||
| [Maven 安装](https://github.com/dunwu/java-tutorial/blob/master/docs/javatool/build/maven/maven-install.md) | Java 构建工具 |
|
||||
| [Nexus 安装](https://github.com/dunwu/java-tutorial/blob/master/docs/javatool/build/maven/nexus.md) | Maven 私服 |
|
||||
| [Nginx 教程](https://github.com/dunwu/nginx-tutorial) | 反向代理服务器 |
|
||||
| [Nodejs 安装](docs/linux/ops/soft/nodejs.md) | 不解释 |
|
||||
| [RocketMQ 安装](docs/linux/ops/soft/rocketmq.md) | 阿里巴巴开源的消息中间件。 |
|
||||
| [Svn 安装](docs/linux/ops/soft/svn.md) | Svn 是 Subversion 的简称,是一个开放源代码的版本控制系统,它采用了分支管理系统。 |
|
||||
| [Tomcat 安装](docs/linux/ops/soft/tomcat.md) | Java 应用服务器 |
|
||||
| [Zookeeper 安装](docs/linux/ops/soft/zookeeper.md) | 分布式系统协调软件 |
|
||||
|
||||
### [Windows](docs/windows)
|
||||
|
||||
- [Windows 工具](docs/windows/Windows工具.md)
|
||||
|
||||
### [Docker](docs/docker)
|
||||
## [Docker](docs/docker)
|
||||
|
|
|
@ -11,8 +11,8 @@
|
|||
执行以下任意命令即可执行安装脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/zsh-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/zsh-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/zsh-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/zsh-install.sh | bash
|
||||
```
|
||||
|
||||
## JDK8 安装
|
||||
|
@ -26,8 +26,8 @@ JDK8 会被安装到 `/usr/lib/jvm/java` 路径。
|
|||
执行以下任意命令即可执行安装脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/jdk8-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/jdk8-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/jdk8-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/jdk8-install.sh | bash
|
||||
```
|
||||
|
||||
## Maven 安装配置
|
||||
|
@ -42,8 +42,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
执行以下任意命令即可执行安装脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/maven-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/maven-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/maven-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/maven-install.sh | bash
|
||||
```
|
||||
|
||||
## Node.js 安装
|
||||
|
@ -57,8 +57,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
执行以下任意命令即可执行安装脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/nodejs-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/nodejs-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/nodejs-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/nodejs-install.sh | bash
|
||||
```
|
||||
|
||||
## MongoDB 安装
|
||||
|
@ -72,8 +72,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
执行以下任意命令即可执行安装脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash
|
||||
```
|
||||
|
||||
## Redis 安装
|
||||
|
@ -87,8 +87,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
执行以下任意命令即可执行安装脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash
|
||||
```
|
||||
|
||||
## Tomcat8 安装
|
||||
|
@ -100,8 +100,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
使用方法:
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/tomcat8-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/tomcat8-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/tomcat8-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/tomcat8-install.sh | bash
|
||||
```
|
||||
|
||||
## Kafka 安装
|
||||
|
@ -113,8 +113,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/kafka-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/kafka-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/kafka-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/kafka-install.sh | bash
|
||||
```
|
||||
|
||||
## RocketMQ 安装
|
||||
|
@ -126,8 +126,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/rocketmq-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/rocketmq-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/rocketmq-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/rocketmq-install.sh | bash
|
||||
```
|
||||
|
||||
## ZooKeeper 安装
|
||||
|
@ -139,7 +139,7 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/zookeeper-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/zookeeper-install.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/zookeeper-install.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/zookeeper-install.sh | bash
|
||||
```
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ replaceLogstashConfig() {
|
|||
sed -i "s/# http.host: \"127.0.0.1\"/ http.host: ${IP}/g" ${ELASTIC_SOFTWARE_PATH}/logstash-${version}/config/logstash.yml
|
||||
touch ${ELASTIC_SOFTWARE_PATH}/logstash-${version}/bin/nohup.out
|
||||
cd ${ELASTIC_SOFTWARE_PATH}/logstash-${version}/bin
|
||||
wget "https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/elk/config/logstash.conf"
|
||||
wget "https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/elk/config/logstash.conf"
|
||||
}
|
||||
|
||||
# 替换 Kibana 配置
|
||||
|
@ -125,6 +125,6 @@ replaceFilebeatConfig
|
|||
|
||||
# 最后,将启动脚本下载到本地
|
||||
mkdir -p /home/zp/script
|
||||
wget -P /home/zp/script "https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/elk/boot-elk.sh"
|
||||
wget -P /home/zp/script "https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/elk/boot-elk.sh"
|
||||
#setPrivilegeForUser
|
||||
|
||||
|
|
|
@ -17,16 +17,16 @@ do
|
|||
path=$(cd "$(dirname "$0")"; pwd)
|
||||
case ${item} in
|
||||
"git") yum install -y git ;;
|
||||
"zsh") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/zsh-install.sh | bash ;;
|
||||
"jdk") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/jdk8-install.sh | bash ;;
|
||||
"maven") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/maven-install.sh | bash ;;
|
||||
"nodejs") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/nodejs-install.sh | bash ;;
|
||||
"mongodb") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash ;;
|
||||
"redis") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash ;;
|
||||
"tomcat") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/tomcat8-install.sh | bash ;;
|
||||
"kafka") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/kafka-install.sh | bash ;;
|
||||
"rocketmq") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/rocketmq-install.sh | bash ;;
|
||||
"zookeeper") curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/zookeeper-install.sh | bash ;;
|
||||
"zsh") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/zsh-install.sh | bash ;;
|
||||
"jdk") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/jdk8-install.sh | bash ;;
|
||||
"maven") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/maven-install.sh | bash ;;
|
||||
"nodejs") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/nodejs-install.sh | bash ;;
|
||||
"mongodb") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/mongodb-install.sh | bash ;;
|
||||
"redis") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/redis-install.sh | bash ;;
|
||||
"tomcat") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/tomcat8-install.sh | bash ;;
|
||||
"kafka") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/kafka-install.sh | bash ;;
|
||||
"rocketmq") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/rocketmq-install.sh | bash ;;
|
||||
"zookeeper") curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/zookeeper-install.sh | bash ;;
|
||||
*)
|
||||
echo -e "输入项不支持!"
|
||||
main
|
||||
|
|
|
@ -38,6 +38,6 @@ source /etc/profile
|
|||
# 备份并替换 settings.xml,使用 aliyun 镜像加速 maven
|
||||
echo -e "\n>>>>>>>>> replace ${path}/conf/settings.xml"
|
||||
cp ${path}/conf/settings.xml ${path}/conf/settings.xml.bak
|
||||
wget -N https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/config/settings-aliyun.xml -O ${path}/conf/settings.xml
|
||||
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/config/settings-aliyun.xml -O ${path}/conf/settings.xml
|
||||
|
||||
mvn -v
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
使用方法:
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/nginx/install-nginx.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/nginx/install-nginx.sh | bash
|
||||
```
|
||||
|
||||
脚本会下载解压 nginx 到 `/opt/nginx` 路径下。
|
||||
|
@ -15,6 +15,6 @@ curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/
|
|||
使用方法:
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/nginx/install-nginx-by-yum.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/nginx/install-nginx-by-yum.sh | bash
|
||||
```
|
||||
|
||||
|
|
|
@ -17,4 +17,4 @@ fi
|
|||
|
||||
echo -e "\n>>>>>>>>> config redis"
|
||||
cp ${path}/redis.conf ${path}/redis.conf.default
|
||||
wget -N https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/soft/config/redis-remote-access.conf -O ${path}/redis.conf
|
||||
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/soft/config/redis-remote-access.conf -O ${path}/redis.conf
|
||||
|
|
|
@ -20,8 +20,8 @@
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
|
||||
```
|
||||
|
||||
## 安装基本工具(可选)
|
||||
|
@ -45,8 +45,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/install-tools.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/install-tools.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-tools.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-tools.sh | bash
|
||||
```
|
||||
|
||||
## 安装常见 lib
|
||||
|
@ -63,8 +63,8 @@ lib 清单(可以根据需要,在 install-libs.sh 中把不需要的工具
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/install-libs.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/install-libs.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-libs.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/install-libs.sh | bash
|
||||
```
|
||||
|
||||
## 关闭防火墙
|
||||
|
@ -72,8 +72,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/stop-firewall.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/stop-firewall.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/stop-firewall.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/stop-firewall.sh | bash
|
||||
```
|
||||
|
||||
## 设置 DNS
|
||||
|
@ -81,8 +81,8 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/set-dns.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/set-dns.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/set-dns.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/set-dns.sh | bash
|
||||
```
|
||||
|
||||
## 设置 ntp
|
||||
|
@ -90,6 +90,6 @@ wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/set-ntp.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/set-ntp.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/set-ntp.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/set-ntp.sh | bash
|
||||
```
|
||||
|
|
|
@ -7,6 +7,6 @@
|
|||
使用方法:执行以下任意命令即可执行脚本。
|
||||
|
||||
```sh
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
|
||||
curl -o- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
|
||||
wget -qO- https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/yum/change-yum-repo.sh | bash
|
||||
```
|
||||
|
|
|
@ -23,7 +23,7 @@ cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
|
|||
# 根据发型版本选择相应 yum 镜像
|
||||
if [[ ${version} == 5 ]]; then
|
||||
# Cento5 已废弃,只能使用 http://vault.CentOS.org/ 替换,但由于是国外镜像,速度较慢
|
||||
wget -N https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/yum/Centos-5.repo -O /etc/yum.repos.d/CentOS-Base.repo
|
||||
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/yum/Centos-5.repo -O /etc/yum.repos.d/CentOS-Base.repo
|
||||
|
||||
# 根据实际发型版本情况替换
|
||||
detailVersion=`lsb_release -r | awk '{print substr($2,1,3)}'`
|
||||
|
@ -32,9 +32,9 @@ if [[ ${version} == 5 ]]; then
|
|||
# 不替换下面的开关,可能会出现错误:Could not open/read repomd.xml
|
||||
sed -i 's/enabled=1/enabled=0/g' /etc/yum.repos.d/CentOS-Media.repo
|
||||
elif [[ ${version} == 6 ]]; then
|
||||
wget -N https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/yum/Centos-6.repo -O /etc/yum.repos.d/CentOS-Base.repo
|
||||
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/yum/Centos-6.repo -O /etc/yum.repos.d/CentOS-Base.repo
|
||||
elif [[ ${version} == 7 ]]; then
|
||||
wget -N https://raw.githubusercontent.com/dunwu/os-tutorial/master/codes/linux/ops/sys/yum/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
|
||||
wget -N https://raw.githubusercontent.com/dunwu/linux-tutorial/master/codes/linux/ops/sys/yum/Centos-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
|
||||
else
|
||||
echo -e "版本不支持,替换 yum repo 失败"
|
||||
fi
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
# Shell 示例源码
|
||||
|
||||
> 本目录的代码是和 『[一篇文章让你彻底掌握 shell 语言](https://github.com/dunwu/os-tutorial/blob/master/docs/linux/scripts/shell.md)』 相配套的示例代码。
|
||||
> 本目录的代码是和 『[一篇文章让你彻底掌握 shell 语言](https://github.com/dunwu/linux-tutorial/blob/master/docs/linux/scripts/shell.md)』 相配套的示例代码。
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# 操作系统
|
||||
|
||||
> :dart: 所有配套源码整理归档在 [**os-tutorial**](https://github.com/dunwu/os-tutorial) 项目中。
|
||||
> :dart: 所有配套源码整理归档在 [**linux-tutorial**](https://github.com/dunwu/linux-tutorial) 项目中。
|
||||
|
||||
## :memo: 知识点
|
||||
|
||||
|
@ -12,4 +12,4 @@
|
|||
|
||||
## :door: 传送门
|
||||
|
||||
| [回首頁](https://github.com/dunwu/os-tutorial) |
|
||||
| [回首頁](https://github.com/dunwu/linux-tutorial) |
|
||||
|
|
|
@ -90,4 +90,4 @@
|
|||
|
||||
## :door: 传送门
|
||||
|
||||
| [回首頁](https://github.com/dunwu/os-tutorial) |
|
||||
| [回首頁](https://github.com/dunwu/linux-tutorial) |
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
> 本文主要介绍 bash 的语法,对于 linux 指令不做任何介绍。
|
||||
>
|
||||
> :notebook: 本文已归档到:「[blog](https://github.com/dunwu/blog)」
|
||||
> :keyboard: 本文的源码已归档到 [os-tutorial](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos)
|
||||
> :keyboard: 本文的源码已归档到 [linux-tutorial](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos)
|
||||
|
||||
```
|
||||
███████╗██╗ ██╗███████╗██╗ ██╗
|
||||
|
@ -173,7 +173,7 @@ chmod +x /path/to/script.sh #使脚本具有执行权限
|
|||
|
||||
这种方式要求脚本文件的第一行必须指明运行该脚本的程序,比如:
|
||||
|
||||
**:keyboard: 『示例源码』** [helloworld.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos/helloworld.sh)
|
||||
**:keyboard: 『示例源码』** [helloworld.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos/helloworld.sh)
|
||||
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
|
@ -207,7 +207,7 @@ shell 语法中,注释是特殊的语句,会被 shell 解释器忽略。
|
|||
- 单行注释 - 以 `#` 开头,到行尾结束。
|
||||
- 多行注释 - 以 `:<<EOF` 开头,到 `EOF` 结束。
|
||||
|
||||
**:keyboard: 『示例源码』** [comment-demo.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos/comment-demo.sh)
|
||||
**:keyboard: 『示例源码』** [comment-demo.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos/comment-demo.sh)
|
||||
|
||||
```bash
|
||||
#--------------------------------------------
|
||||
|
@ -293,7 +293,7 @@ echo `pwd`
|
|||
# Output:(当前目录路径)
|
||||
```
|
||||
|
||||
**:keyboard: 『示例源码』** [echo-demo.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos/echo-demo.sh)
|
||||
**:keyboard: 『示例源码』** [echo-demo.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos/echo-demo.sh)
|
||||
|
||||
### 2.4. printf
|
||||
|
||||
|
@ -301,7 +301,7 @@ printf 用于格式化输出字符串。
|
|||
|
||||
默认,printf 不会像 echo 一样自动添加换行符,如果需要换行可以手动添加 `\n`。
|
||||
|
||||
**:keyboard: 『示例源码』** [printf-demo.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos/printf-demo.sh)
|
||||
**:keyboard: 『示例源码』** [printf-demo.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos/printf-demo.sh)
|
||||
|
||||
```bash
|
||||
# 单引号
|
||||
|
@ -433,7 +433,7 @@ echo ${dword}
|
|||
|
||||
### 3.6. 变量示例源码
|
||||
|
||||
**⌨️ 『示例源码』** [variable-demo.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos/variable-demo.sh)
|
||||
**⌨️ 『示例源码』** [variable-demo.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos/variable-demo.sh)
|
||||
|
||||
## 4. 字符串
|
||||
|
||||
|
@ -507,7 +507,7 @@ echo `expr index "${text}" ll`
|
|||
|
||||
### 4.6. 字符串示例源码
|
||||
|
||||
**⌨️ 『示例源码』** [string-demo.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos/string-demo.sh)
|
||||
**⌨️ 『示例源码』** [string-demo.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos/string-demo.sh)
|
||||
|
||||
## 5. 数组
|
||||
|
||||
|
@ -619,7 +619,7 @@ echo ${nums[@]}
|
|||
|
||||
### 5.6. 数组示例源码
|
||||
|
||||
**:keyboard: 『示例源码』** [array-demo.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos/array-demo.sh)
|
||||
**:keyboard: 『示例源码』** [array-demo.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos/array-demo.sh)
|
||||
|
||||
## 6. 运算符
|
||||
|
||||
|
@ -640,7 +640,7 @@ echo ${nums[@]}
|
|||
|
||||
**注意:**条件表达式要放在方括号之间,并且要有空格,例如: `[$x==$y]` 是错误的,必须写成 `[ $x == $y ]`。
|
||||
|
||||
**:keyboard: 『示例源码』** [operator-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/operator/operator-demo.sh)
|
||||
**:keyboard: 『示例源码』** [operator-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/operator/operator-demo.sh)
|
||||
|
||||
```bash
|
||||
x=10
|
||||
|
@ -698,7 +698,7 @@ fi
|
|||
| `-ge` | 检测左边的数是否大于等于右边的,如果是,则返回 true。 | `[ $a -ge $b ]` 返回 false。 |
|
||||
| `-le` | 检测左边的数是否小于等于右边的,如果是,则返回 true。 | `[ $a -le $b ]`返回 true。 |
|
||||
|
||||
**:keyboard: 『示例源码』** [operator-demo2.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/operator/operator-demo2.sh)
|
||||
**:keyboard: 『示例源码』** [operator-demo2.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/operator/operator-demo2.sh)
|
||||
|
||||
```bash
|
||||
x=10
|
||||
|
@ -763,7 +763,7 @@ fi
|
|||
| `-o` | 或运算,有一个表达式为 true 则返回 true。 | `[ $a -lt 20 -o $b -gt 100 ]` 返回 true。 |
|
||||
| `-a` | 与运算,两个表达式都为 true 才返回 true。 | `[ $a -lt 20 -a $b -gt 100 ]` 返回 false。 |
|
||||
|
||||
**:keyboard: 『示例源码』** [operator-demo3.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/operator/operator-demo3.sh)
|
||||
**:keyboard: 『示例源码』** [operator-demo3.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/operator/operator-demo3.sh)
|
||||
|
||||
```bash
|
||||
x=10
|
||||
|
@ -813,7 +813,7 @@ fi
|
|||
| `&&` | 逻辑的 AND | `[[ ${x} -lt 100 && ${y} -gt 100 ]]` 返回 false |
|
||||
| `||` | 逻辑的 OR | `[[ ${x} -lt 100 || ${y} -gt 100 ]]` 返回 true |
|
||||
|
||||
**:keyboard: 『示例源码』** [operator-demo4.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/operator/operator-demo4.sh)
|
||||
**:keyboard: 『示例源码』** [operator-demo4.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/operator/operator-demo4.sh)
|
||||
|
||||
```bash
|
||||
x=10
|
||||
|
@ -854,7 +854,7 @@ fi
|
|||
| `-n` | 检测字符串长度是否为 0,不为 0 返回 true。 | `[ -n $a ]` 返回 true。 |
|
||||
| `str` | 检测字符串是否为空,不为空返回 true。 | `[ $a ]` 返回 true。 |
|
||||
|
||||
**:keyboard: 『示例源码』** [operator-demo5.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/operator/operator-demo5.sh)
|
||||
**:keyboard: 『示例源码』** [operator-demo5.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/operator/operator-demo5.sh)
|
||||
|
||||
```bash
|
||||
x="abc"
|
||||
|
@ -925,7 +925,7 @@ fi
|
|||
| -s file | 检测文件是否为空(文件大小是否大于 0),不为空返回 true。 | `[ -s $file ]` 返回 true。 |
|
||||
| -e file | 检测文件(包括目录)是否存在,如果是,则返回 true。 | `[ -e $file ]` 返回 true。 |
|
||||
|
||||
**:keyboard: 『示例源码』** [operator-demo6.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/operator/operator-demo6.sh)
|
||||
**:keyboard: 『示例源码』** [operator-demo6.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/operator/operator-demo6.sh)
|
||||
|
||||
```bash
|
||||
file="/etc/hosts"
|
||||
|
@ -1036,13 +1036,13 @@ fi
|
|||
# Output: 10 < 20
|
||||
```
|
||||
|
||||
**:keyboard: 『示例源码』** [if-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/statement/if-demo.sh)
|
||||
**:keyboard: 『示例源码』** [if-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/statement/if-demo.sh)
|
||||
|
||||
#### `case`
|
||||
|
||||
如果你需要面对很多情况,分别要采取不同的措施,那么使用`case`会比嵌套的`if`更有用。使用`case`来解决复杂的条件判断,看起来像下面这样:
|
||||
|
||||
**:keyboard: 『示例源码』** [case-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/statement/case-demo.sh)
|
||||
**:keyboard: 『示例源码』** [case-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/statement/case-demo.sh)
|
||||
|
||||
```bash
|
||||
exec
|
||||
|
@ -1114,7 +1114,7 @@ done
|
|||
# 将 /home/zp 目录下所有 sh 文件拷贝到 /home/zp/scripts
|
||||
```
|
||||
|
||||
**:keyboard: 『示例源码』** [for-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/statement/for-demo.sh)
|
||||
**:keyboard: 『示例源码』** [for-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/statement/for-demo.sh)
|
||||
|
||||
#### `while`循环
|
||||
|
||||
|
@ -1151,7 +1151,7 @@ done
|
|||
# 81
|
||||
```
|
||||
|
||||
**:keyboard: 『示例源码』** [while-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/statement/while-demo.sh)
|
||||
**:keyboard: 『示例源码』** [while-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/statement/while-demo.sh)
|
||||
|
||||
#### `until`循环
|
||||
|
||||
|
@ -1171,7 +1171,7 @@ done
|
|||
# 4
|
||||
```
|
||||
|
||||
**:keyboard: 『示例源码』** [until-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/statement/until-demo.sh)
|
||||
**:keyboard: 『示例源码』** [until-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/statement/until-demo.sh)
|
||||
|
||||
#### `select`循环
|
||||
|
||||
|
@ -1219,7 +1219,7 @@ Choose the package manager: 2
|
|||
Enter the package name: gitbook-cli
|
||||
```
|
||||
|
||||
**:keyboard: 『示例源码』** [select-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/statement/select-demo.sh)
|
||||
**:keyboard: 『示例源码』** [select-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/statement/select-demo.sh)
|
||||
|
||||
#### `break` 和 `continue`
|
||||
|
||||
|
@ -1229,7 +1229,7 @@ Enter the package name: gitbook-cli
|
|||
>
|
||||
> `continue`语句用来跳过某次迭代。
|
||||
|
||||
**:keyboard: 『示例源码』** [break-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/statement/break-demo.sh)
|
||||
**:keyboard: 『示例源码』** [break-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/statement/break-demo.sh)
|
||||
|
||||
```bash
|
||||
# 查找 10 以内第一个能整除 2 和 3 的正整数
|
||||
|
@ -1244,7 +1244,7 @@ done
|
|||
# Output: 6
|
||||
```
|
||||
|
||||
**:keyboard: 『示例源码』** [continue-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/statement/continue-demo.sh)
|
||||
**:keyboard: 『示例源码』** [continue-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/statement/continue-demo.sh)
|
||||
|
||||
```bash
|
||||
# 打印10以内的奇数
|
||||
|
@ -1280,7 +1280,7 @@ bash 函数定义语法如下:
|
|||
> 3. 函数返回值在调用该函数后通过 `$?` 来获得。
|
||||
> 4. 所有函数在使用前必须定义。这意味着必须将函数放在脚本开始部分,直至 shell 解释器首次发现它时,才可以使用。调用函数仅使用其函数名即可。
|
||||
|
||||
**:keyboard: 『示例源码』** [function-demo.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos//function/function-demo.sh)
|
||||
**:keyboard: 『示例源码』** [function-demo.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos//function/function-demo.sh)
|
||||
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
|
@ -1346,7 +1346,7 @@ the result is: 100
|
|||
| `$#` | 不包括`$0`在内的位置参数的个数 |
|
||||
| `$FUNCNAME` | 函数名称(仅在函数内部有值) |
|
||||
|
||||
**:keyboard: 『示例源码』** [function-demo2.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos//function/function-demo2.sh)
|
||||
**:keyboard: 『示例源码』** [function-demo2.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos//function/function-demo2.sh)
|
||||
|
||||
```bash
|
||||
#!/usr/bin/env bash
|
||||
|
@ -1406,7 +1406,7 @@ $ ./function-demo2.sh 10 20
|
|||
| `$-` | 返回 Shell 使用的当前选项,与 set 命令功能相同。 |
|
||||
| `$?` | 函数返回值 |
|
||||
|
||||
**:keyboard: 『示例源码』** [function-demo3.sh](https://github.com/dunwu/os-tutorial/tree/master/codes/shell/demos//function/function-demo3.sh)
|
||||
**:keyboard: 『示例源码』** [function-demo3.sh](https://github.com/dunwu/linux-tutorial/tree/master/codes/shell/demos//function/function-demo3.sh)
|
||||
|
||||
```bash
|
||||
runner() {
|
||||
|
@ -1644,7 +1644,7 @@ $ ./my_script
|
|||
|
||||
有时我们值需要 debug 脚本的一部分。这种情况下,使用`set`命令会很方便。这个命令可以启用或禁用选项。使用`-`启用选项,`+`禁用选项:
|
||||
|
||||
**:keyboard: 『示例源码』** [debug-demo.sh](https://github.com/dunwu/os-tutorial/blob/master/codes/shell/demos/debug-demo.sh)
|
||||
**:keyboard: 『示例源码』** [debug-demo.sh](https://github.com/dunwu/linux-tutorial/blob/master/codes/shell/demos/debug-demo.sh)
|
||||
|
||||
```bash
|
||||
# 开启 debug
|
||||
|
|
Loading…
Reference in New Issue