File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change
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
+ - <>
You can’t perform that action at this time.
0 commit comments