Skip to content

Commit 34b0479

Browse files
committed
2017-06-21
1 parent 9ae9e0b commit 34b0479

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Shell.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Shell 脚本编程
2+
3+
## 环境
4+
5+
- CentOS 7.3
6+
- bash + zsh
7+
- IntelliJ IDEA 2017.1 + Vim
8+
- Xshell 5
9+
10+
## 基础
11+
12+
- 查看 bash 版本号:`bash --version`,CentOS 7.3 是 4.2.46
13+
- 查看 zsh 版本号:`zsh --version`
14+
- 文件后缀:`sh`
15+
- 开头语言标识。文件开头是:`#!/bin/sh``#!/bin/bash`(优先)(其实也可以不加,因为 Linux 默认就是 bash,只是为了合理,一般都要加),主要是告诉哪个解析器来执行脚本。如果该语句写在非第一行,那就是当做注释使用。
16+
- 其中 /bin/sh 是 bash 的软链接,所以以上两种写法都可以。(证明:`ls -l /bin/sh`)
17+
- 换行符(line separator):IntelliJ IDEA 下编写脚本的时候一定要注意后下角的 LF 还是 CRLF,LF 才是 Linux 的要求。
18+
- 执行脚本命令:`bash /opt/test.sh`(推荐),还有:`. /opt/test.sh``source /opt/test.sh`
19+
- 用 source 或是 点开头 的优点是:后面执行的脚本可以读取 source 或 点 执行脚本中的变量内容
20+
- 注释:用 # 号开头
21+
- 如果脚本是用于 Crontab 定时任务,则定义在 /etc/profile 中的环境变量是无法使用的,需要重新定义。
22+
23+
24+
25+
26+
27+
28+
29+
30+
## 资料
31+
32+
- <>

0 commit comments

Comments
 (0)