-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path16.html
More file actions
278 lines (278 loc) · 21.5 KB
/
Copy path16.html
File metadata and controls
278 lines (278 loc) · 21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="CodeClub - Shell 教程" />
<meta name="author" content="Jackson" />
<title>Shell 教程 - CodeClub</title>
<link rel="icon" type="image/x-icon" href="../../img/logo.png" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap"
rel="stylesheet"
/>
<link
rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css"
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<link rel="stylesheet" href="../../css/main.css" />
<link rel="stylesheet" href="../../css/dark-mode.css" />
<link rel="stylesheet" href="../../css/mobile-optimizations.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.0/marked.min.js"></script>
<style>
.tutorial-page {
max-width: 1200px;
margin: 70px auto 40px;
padding: 0 20px;
display: flex;
gap: 20px;
}
.tutorial-sidebar {
width: 240px;
flex-shrink: 0;
position: sticky;
top: 70px;
max-height: calc(100vh - 90px);
overflow-y: auto;
background: var(--bg-secondary, #fff);
border-radius: 8px;
padding: 16px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.tutorial-sidebar h3 {
font-size: 15px;
margin: 0 0 12px;
color: var(--text-primary, #1a1a2e);
padding-bottom: 8px;
border-bottom: 2px solid var(--primary, #3b82f6);
}
.tutorial-sidebar a {
display: block;
padding: 5px 8px;
color: var(--text-secondary, #666);
text-decoration: none;
font-size: 13px;
border-radius: 4px;
line-height: 1.4;
}
.tutorial-sidebar a:hover {
background: var(--primary, #3b82f6);
color: #fff;
}
.tutorial-sidebar a.active {
background: var(--primary, #3b82f6);
color: #fff;
font-weight: 600;
}
.tutorial-main {
flex: 1;
min-width: 0;
}
.tutorial-article {
background: var(--bg-secondary, #fff);
border-radius: 8px;
padding: 32px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.tutorial-article h1 {
font-size: 26px;
margin-bottom: 16px;
color: var(--text-primary, #1a1a2e);
border-bottom: 2px solid var(--primary, #3b82f6);
padding-bottom: 12px;
}
.markdown-body {
font-size: 15px;
line-height: 1.8;
color: var(--text-secondary, #333);
}
.markdown-body h1 {
font-size: 24px;
border-bottom: 1px solid var(--border, #e5e7eb);
padding-bottom: 8px;
}
.markdown-body h2 {
font-size: 20px;
border-bottom: 1px solid var(--border, #e5e7eb);
padding-bottom: 6px;
}
.markdown-body h3 {
font-size: 17px;
}
.markdown-body pre {
background: #1e1e2e;
color: #cdd6f4;
padding: 16px;
border-radius: 8px;
overflow-x: auto;
}
.markdown-body code {
font-family: 'Fira Code', 'Cascadia Code', monospace;
font-size: 14px;
}
.markdown-body p code {
background: #f1f5f9;
padding: 2px 6px;
border-radius: 4px;
color: #e83e8c;
}
.markdown-body blockquote {
border-left: 4px solid var(--primary, #3b82f6);
padding: 12px 20px;
margin: 16px 0;
background: #f8fafc;
border-radius: 0 8px 8px 0;
}
.markdown-body img {
max-width: 100%;
border-radius: 8px;
}
.markdown-body table {
border-collapse: collapse;
width: 100%;
margin: 16px 0;
}
.markdown-body table th,
.markdown-body table td {
border: 1px solid var(--border, #e5e7eb);
padding: 8px 12px;
text-align: left;
}
.markdown-body table th {
background: var(--bg-primary, #f8fafc);
font-weight: 600;
}
.markdown-body table tr:nth-child(2n) {
background: var(--bg-primary, #f8fafc);
}
.markdown-body ul,
.markdown-body ol {
padding-left: 24px;
margin: 12px 0;
}
.markdown-body li {
margin: 4px 0;
}
.markdown-body hr {
border: none;
border-top: 1px solid var(--border, #e5e7eb);
margin: 24px 0;
}
.markdown-body a {
color: var(--primary, #3b82f6);
text-decoration: none;
}
.markdown-body a:hover {
text-decoration: underline;
}
.page-navigation {
display: flex;
justify-content: space-between;
margin-top: 24px;
padding-top: 16px;
border-top: 1px solid var(--border, #e5e7eb);
}
.page-nav-link {
color: var(--primary, #3b82f6);
text-decoration: none;
font-weight: 500;
font-size: 14px;
}
.page-nav-link:hover {
text-decoration: underline;
}
.source-link {
margin-top: 16px;
font-size: 13px;
color: var(--text-secondary, #999);
}
.source-link a {
color: var(--primary, #3b82f6);
}
@media (max-width: 768px) {
.tutorial-page {
flex-direction: column;
}
.tutorial-sidebar {
width: 100%;
position: static;
max-height: 200px;
}
}
</style>
</head>
<body>
<nav class="navbar">
<div class="navbar-container">
<a class="navbar-brand" href="../../index.html">
<img src="../../img/logo.png" alt="CodeClub" width="32" height="32" />
<span>CodeClub</span>
</a>
<button class="mobile-menu-toggle" aria-label="切换导航菜单"><span></span><span></span><span></span></button>
<ul class="navbar-nav">
<li><a class="nav-link" href="../../index.html">首页</a></li>
<li><a class="nav-link" href="../../nav.html">网址导航</a></li>
<li><a class="nav-link" href="../../blog/">博客</a></li>
<li><a class="nav-link" href="../../wiki/index.html" target="_blank">WiKi</a></li>
<li><a class="nav-link active" href="../index.html">教程</a></li>
<li><a class="nav-link" href="../../book.html">图书</a></li>
<li><a class="nav-link" href="../../contact.html">联系我</a></li>
<li><a class="nav-link" href="../../about.html">关于我</a></li>
</ul>
</div>
</nav>
<div class="tutorial-page">
<div class="tutorial-sidebar">
<h3>📖 Shell</h3>
<a href="0.html">Linux</a>
<a href="1.html">Linux 简介</a>
<a href="2.html">Linux 安装</a>
<a href="3.html">Linux 云服务器</a>
<a href="4.html">WSL 安装 Linux</a>
<a href="5.html">Linux 系统启动过程</a>
<a href="6.html">Linux 系统目录结构</a>
<a href="7.html">Linux 忘记密码解决方法</a>
<a href="8.html">Linux 远程登录</a>
<a href="9.html">Linux 文件基本属性</a>
<a href="10.html">Linux 文件与目录管理</a>
<a href="11.html">Linux 用户和用户组管理</a>
<a href="12.html">Linux 磁盘管理</a>
<a href="13.html">Linux vi/vim</a>
<a href="14.html">linux yum 命令</a>
<a href="15.html">Linux apt 命令</a>
<a href="16.html" class="active">Shell 教程</a>
<a href="17.html">Shell 变量</a>
<a href="18.html">Shell echo 命令</a>
<a href="19.html">Shell test 命令</a>
<a href="20.html">Shell 流程控制</a>
<a href="21.html">Shell 函数</a>
<a href="22.html">Linux 命令大全</a>
<a href="23.html">Nginx 安装配置</a>
<a href="24.html">MySQL 安装配置</a>
</div>
<div class="tutorial-main">
<div class="tutorial-article">
<div class="markdown-body" id="md-content"></div>
<div class="page-navigation">
<a href="15.html" class="page-nav-link">← Linux apt 命令</a>
<a href="17.html" class="page-nav-link">Shell 变量 →</a>
</div>
<div class="source-link">原文来源:<a href="https://www.runoob.com" target="_blank">菜鸟教程</a></div>
</div>
</div>
</div>
<footer class="footer">
<div class="footer-content"><p>© 2024 CodeClub. All rights reserved.</p></div>
</footer>
<script src="../../js/dark-mode.js"></script>
<script src="../../js/mobile-menu.js"></script>
<script>
const md = `Shell 教程\nShell 是一个用 C 语言编写的程序,它是用户使用 Linux 的桥梁。Shell 既是一种命令语言,又是一种程序设计语言。\n\n\nShell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。\n\n\nKen Thompson 的 sh 是第一种 Unix Shell,Windows Explorer 是一个典型的图形界面 Shell。\n\n\n[**Shell 在线工具**](https://www.runoob.com/try/showbash.php?filename=helloworld)\n\n\n\n---\n\n\n## Shell 脚本\n\nShell 脚本(shell script),是一种为 shell 编写的脚本程序。\n\n\n业界所说的 shell 通常都是指 shell 脚本,但读者朋友要知道,shell 和 shell script 是两个不同的概念。\n\n\n由于习惯的原因,简洁起见,本文出现的 "shell编程" 都是指 shell 脚本编程,不是指开发 shell 自身。\n\n\n\n\n---\n\n\n## Shell 环境\n\nShell 编程跟 JavaScript、php 编程一样,只要有一个能编写代码的文本编辑器和一个能解释执行的脚本解释器就可以了。\n\n\nLinux 的 Shell 种类众多,常见的有:\n\n\n\n\n\n- Bourne Shell(/usr/bin/sh或/bin/sh)\n- \nBourne Again Shell(/bin/bash)\n- C Shell(/usr/bin/csh)\n- K Shell(/usr/bin/ksh)\n- Shell for Root(/sbin/sh)\n- ……\n\n\n本教程关注的是 Bash,也就是 Bourne Again Shell,由于易用和免费,Bash 在日常工作中被广泛使用。同时,Bash 也是大多数Linux 系统默认的 Shell。\n\n\n在一般情况下,人们并不区分 Bourne Shell 和 Bourne Again Shell,所以,像 **#!/bin/sh**,它同样也可以改为 **#!/bin/bash**。\n\n\n#! 告诉系统其后路径所指定的程序即是解释此脚本文件的 Shell 程序。\n\n\n\n---\n\n\n## 第一个shell脚本\n\n打开文本编辑器(可以使用 vi/vim 命令来创建文件),新建一个文件 test.sh,扩展名为 sh(sh代表shell),扩展名并不影响脚本执行,见名知意就好,如果你用 php 写 shell 脚本,扩展名就用 php 好了。\n\n\n输入一些代码,第一行一般是这样:\n\n\n\n\n## 实例\n\n\n\n#!/bin/bash**\necho "Hello World !"\n\n\n\n\n[运行实例 »](https://www.runoob.com/try/runcode.php?filename=helloworld&type=bash)\n\n#! 是一个约定的标记,它告诉系统这个脚本需要什么解释器来执行,即使用哪一种 Shell。\n\n\necho 命令用于向窗口输出文本。\n\n\n\n### 运行 Shell 脚本有两种方法:\n\n**1、作为可执行程序**\n\n\n\n将上面的代码保存为 test.sh,并 cd 到相应目录:\n\n\n\n\`\`\`\n\nchmod +x ./test.sh #使脚本具有执行权限\n./test.sh #执行脚本\n\n\`\`\`\n\n注意,一定要写成 ./test.sh,而不是 test.sh**,运行其它二进制的程序也一样,直接写 test.sh,linux 系统会去 PATH 里寻找有没有叫 test.sh 的,而只有 /bin, /sbin, /usr/bin,/usr/sbin 等在 PATH 里,你的当前目录通常不在 PATH 里,所以写成 test.sh 是会找不到命令的,要用 ./test.sh 告诉系统说,就在当前目录找。\n\n\n\n**2、作为解释器参数**\n\n\n\n\n这种运行方式是,直接运行解释器,其参数就是 shell 脚本的文件名,如:\n\n\n\n\`\`\`\n\n/bin/sh test.sh\n/bin/php test.php\n\n\`\`\`\n\n\n这种方式运行的脚本,不需要在第一行指定解释器信息,写了也没用。\n\n \n \n \n \n \n\n \n \n [ Shell 变量](http://www.runoob.com/linux/linux-shell-variable.html)\n \n\n \n \n \n \n \n\n\n\n\n\n \n## \n \n \n \n 5 篇笔记\n 写笔记\n\n\n\n\n\n \n\n #0 su226\n\n 136***1939@qq.com\n\n [ 参考地址](http://blog.csdn.net/dream_an/article/details/50548936)\n\n 220\n## sh/bash/csh/Tcsh/ksh/pdksh等shell的区别\n\n\n\n- **sh(全称 Bourne Shell)**: 是UNIX最初使用的 shell,而且在每种 UNIX 上都可以使用。\n\nBourne Shell 在 shell 编程方面相当优秀,但在处理与用户的交互方面做得不如其他几种 shell。\n\n- **bash(全称 Bourne Again Shell)**: LinuxOS 默认的,它是 Bourne Shell 的扩展。\n与 Bourne Shell 完全兼容,并且在 Bourne Shell 的基础上增加了很多特性。可以提供命令补全,命令编辑和命令历史等功能。它还包含了很多 C Shell 和 Korn Shell 中的优点,有灵活和强大的编辑接口,同时又很友好的用户界面。\n\n- **csh(全称 C Shell)**: 是一种比 Bourne Shell更适合的变种 Shell,它的语法与 C 语言很相似。\n\n- **Tcsh**: 是 Linux 提供的 C Shell 的一个扩展版本。\n\nTcsh 包括命令行编辑,可编程单词补全,拼写校正,历史命令替换,作业控制和类似 C 语言的语法,他不仅和 Bash Shell 提示符兼容,而且还提供比 Bash Shell 更多的提示符参数。\n- **ksh (全称 Korn Shell)**: 集合了 C Shell 和 Bourne Shell 的优点并且和 Bourne Shell 完全兼容。\n\n- \n**pdksh**: 是 Linux 系统提供的 ksh 的扩展。\n\npdksh 支持人物控制,可以在命令行上挂起,后台执行,唤醒或终止程序。\n[su226](https://www.runoob.com/note/1426) su226\n\n 136***1939@qq.com\n\n [ 参考地址](http://blog.csdn.net/dream_an/article/details/50548936)\n\n9年前 (2017-03-12)\n#0 lyphp\n\n 882***68@qq.com\n\n 130如果不好理解的话,Shell 个人感觉可以对应成 win 中的 bat,通过代码来实现一些自动定时任务,自动备份或者执行的任务。\n\n\n\n1、chmod +x file 加上执行权限,否则会提示无执行权限。\n\n\n\n2、注意执行脚本时候或者全目录,或者 ./file.sh ,如果不加的话,linux 默认会从PATH 里去找该 file.sh。\n\n\n\n3、看了这篇教程,发现脚本后缀名可以任意修改,仍然可以正常运行。\n\n\n\n4、语法类PHP,方便学习。\n\n[lyphp](https://www.runoob.comjavascript:;) lyphp\n\n 882***68@qq.com\n\n9年前 (2017-07-24)\n#0 gooklim\n\n goo***m1221@gmail.com\n\n [ 参考地址](https://www.zhihu.com/question/19901542)\n\n 151**首先,什么是脚本语言?**\n\n\n\n脚本语言是像剧本一样教计算机办某个事情的语言。\n\n\n\n比如你想让计算机执行复制某个文件的操作,如:cp ~/Desktop/*.txt ~/text\n\n\n\n你可以在文本编辑器写入上边的代码并且保存此文件,然后你通过执行这个文本文件来执行上面的代码,并不需要重复手动输入上边的代码。\n\n\n\n\n\n下面这句话是我在网上看到的:\n\n\n\n所以脚本其实就是短小的、用来让计算机自动化完成一系列工作的程序,这类程序可以用文本编辑器修改,不需要编译,通常是解释运行的。\n\n\n\n[gooklim](https://www.runoob.comjavascript:;) gooklim\n\n goo***m1221@gmail.com\n\n [ 参考地址](https://www.zhihu.com/question/19901542)\n\n9年前 (2017-08-29)\n#0 菠菜\n\n 214***893@qq.com\n\n [ 参考地址](http://www.hongyanliren.com/1622.html)\n\n 162\n## ubuntu(linux)下 source、sh、bash、./ 执行脚本的区别是什么?\n\n**1. source命令用法:**\n\n\n\n\n\`\`\`\nsource FileName\n\`\`\`\n\n\n作用:在当前 bash 环境下读取并执行 FileName 中的命令。该 filename 文件可以无 "执行权限"。\n\n\n\n注:该命令通常用命令 . 来替代。\n\n\n\n**2. sh、bash的命令用法:**\n\n\n\n\n\`\`\`\nsh FileName\n或\nbash FileName\n\`\`\`\n\n\n作用:打开一个子 shell 来读取并执行 FileName 中命令。该 filename 文件可以无 "执行权限"。\n\n\n\n注:运行一个shell脚本时会启动另一个命令解释器。\n\n\n\n**3、./的命令用法:**\n\n\n\n\n\`\`\`\n./FileName\n\`\`\`\n\n\n作用: 打开一个子 shell 来读取并执行 FileName 中命令,该 filename 文件需要 "执行权限"。\n\n\n\n注:运行一个 shell 脚本时会启动另一个命令解释器。\n\n\n[菠菜](https://www.runoob.comjavascript:;) 菠菜\n\n 214***893@qq.com\n\n [ 参考地址](http://www.hongyanliren.com/1622.html)\n\n8年前 (2018-03-21)\n#0 菠菜\n\n 214***893@qq.com\n\n [ 参考地址](https://github.com/qinjx/30min_guides/blob/master/shell.md)\n\n 118\n## shell 和 shell 脚本的概念\n\n\nshell 是指一种应用程序,这个应用程序提供了一个界面,用户通过这个界面访问操作系统内核的服务。Ken Thompson 的 sh 是第一种 Unix Shell,Windows Explorer 是一个典型的图形界面 Shell。\n\n\n\nshell 脚本(shell script),是一种为 shell 编写的脚本程序。业界所说的 shell 通常都是指 shell 脚本,但读者朋友要知道,shell 和 shell script 是两个不同的概念。由于习惯的原因,简洁起见,本文出现的 "shell编程" 都是指 shell 脚本编程,不是指开发 shell 自身(如Windows Explorer扩展开发)。\n\n[菠菜](https://www.runoob.comjavascript:;) 菠菜\n\n 214***893@qq.com\n\n [ 参考地址](https://github.com/qinjx/30min_guides/blob/master/shell.md)\n\n8年前 (2018-03-21)\n \n\n \n \n\n \n \n \n### 点我分享笔记\n\n \n \n \n \n \n \n [取消](https://www.runoob.comjavascript:;)\n\n\n \n \n \n \n \n \n\n\n 分享笔记\n \n \n \n \n \n \n\n 昵称昵称 (必填)\n 邮箱邮箱 (必填)\n 引用地址引用地址\n \n\n \n \n \n \n\n \n \n\n\n\n\n\n\n\n\n\n \n\n \n\n\n\n\n\n\n \n \n \n \n \n \n\n\n \n \n \n \n \n \n \n \n \n\n\n\n\n\n 在线实例\n\n\n ·[HTML 实例](https://www.runoob.com/html/html-examples.html)\n\n\n ·[CSS 实例](https://www.runoob.com/css/css-examples.html)\n\n\n ·[JavaScript 实例](https://www.runoob.com/js/js-examples.html)\n\n\n ·[Ajax 实例](https://www.runoob.com/ajx/ajax-examples.html)\n\n\n ·[jQuery 实例](https://www.runoob.com/jquery/jquery-examples.html)\n\n\n ·[XML 实例](https://www.runoob.com/xml/xml-examples.html)\n\n\n ·[Java 实例](https://www.runoob.com/java/java-examples.html)\n\n\n\n\n\n 字符集&工具\n\n\n · [HTML 字符集设置](https://www.runoob.com/charsets/html-charsets.html)\n\n\n · [HTML ASCII 字符集](https://www.runoob.com/tags/html-ascii.html)\n\n\n · [JS 混淆/加密](https://www.jyshare.com/front-end/6939/)\n\n\n · [PNG/JPEG 图片压缩](https://www.jyshare.com/front-end/6232/)\n\n\n · [HTML 拾色器](https://www.runoob.com/tags/html-colorpicker.html)\n\n\n · [JSON 格式化工具](https://www.jyshare.com/front-end/53)\n\n\n · [随机数生成器](https://www.jyshare.com/front-end/6680/)\n\n\n\n\n 最新更新\n\n\n ·\n [\n OpenCode 自定义... ](http://www.runoob.com/opencode/opencode-custom-tools.html)\n\n\n ·\n [\n OpenCode Skills ](http://www.runoob.com/opencode/opencode-skills.html)\n\n\n ·\n [\n OpenCode MCP 服... ](http://www.runoob.com/opencode/opencode-mcp.html)\n\n\n ·\n [\n OpenCode LSP 服... ](http://www.runoob.com/opencode/opencode-lsp.html)\n\n\n ·\n [\n OpenCode 权限配置 ](http://www.runoob.com/opencode/opencode-permissions.html)\n\n\n ·\n [\n OpenCode 格式化... ](http://www.runoob.com/opencode/opencode-formatter.html)\n\n\n ·\n [\n OpenCode 自定义... ](http://www.runoob.com/opencode/opencode-commands.html)\n\n\n\n\n 站点信息\n\n\n ·\n [意见反馈](https://www.runoob.commailto:admin@runoob.com)\n\n\n ·\n [免责声明](https://www.runoob.com/disclaimer)\n\n\n ·\n [关于我们](https://www.runoob.com/aboutus)\n\n\n ·\n [文章归档](https://www.runoob.com/archives)\n\n\n\n\n\n\n\n **关注微信**\n\n\n\n \n\n\n\n\n\n\n Copyright © 2013-2026 **[菜鸟教程](https://www.runoob.com//www.runoob.com/)** \n **[runoob.com](https://www.runoob.com//www.runoob.com/)** All Rights Reserved. 备案号:[闽ICP备15012807号-1](https://beian.miit.gov.cn/)\n\n\n\n [ ](https://www.runoob.comjavascript:void(0))\n [](https://www.runoob.comjavascript:void(0))\n [](https://www.runoob.comjavascript:void(0))\n\n\n\n#### 微信关注\n\n `;
document.getElementById('md-content').innerHTML = marked.parse(md);
</script>
</body>
</html>