BASH:修订间差异
| (未显示同一用户的4个中间版本) | |||
| 第70行: | 第70行: | ||
</syntaxhighlight>|$|/home/kangkk}} | </syntaxhighlight>|$|/home/kangkk}} | ||
|- | |- | ||
| | | <nowiki><</nowiki> || 将文件的内容传递给命令的标准输入 || {{Shc_out|<syntaxhighlight lang="bash"> | ||
cat < /Users/kangjian/path/doc.txt</syntaxhighlight>|<syntaxhighlight lang="bash">a | |||
b | |||
c | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
|- | |- | ||
| | | <nowiki><<</nowiki> || 表示此处文档 || {{Shc_out|<syntaxhighlight lang="bash"> | ||
cat << STRING_SIGN</syntaxhighlight>|<syntaxhighlight lang="bash" highlight="1-5">a | |||
b | |||
c | |||
d | |||
STRING_SIGN | |||
a | |||
b | |||
c | |||
d | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
可以组合命令直接将输入的文本写入文件中。 | |||
{{shc|<syntaxhighlight lang="bash"> | |||
cat > doc.txt << FILE</syntaxhighlight>|$|/home/kangkk}} | |||
|- | |||
| <nowiki><<<</nowiki> || 传递字符串 || {{Shc_out|<syntaxhighlight lang="bash"> | |||
cat <<< 'hi there'</syntaxhighlight>|<syntaxhighlight lang="bash">hi there | |||
</syntaxhighlight>|$|/home/kangkk}} | |||
|} | |} | ||
2022年11月28日 (一) 14:09的最新版本
GNU Bash
Bash is the GNU Project's shell. Bash is the Bourne Again SHell. Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). It is intended to conform to the IEEE POSIX P1003.2/ISO 9945.2 Shell and Tools standard. It offers functional improvements over sh for both programming and interactive use. In addition, most sh scripts can be run by Bash without modification.
The improvements offered by Bash include:
- Command line editing
- Unlimited size command history
- Job Control
- Shell Functions and Aliases
- Indexed arrays of unlimited size
- Integer arithmetic in any base from two to sixty-four
The maintainer also has a bash page which includes Frequently-Asked-Questions.
Downloading Bash
Bash can be found on the main GNU ftp server: http://ftp.gnu.org/gnu/bash/ (via HTTP) and ftp://ftp.gnu.org/gnu/bash/ (via FTP). It can also be found on the GNU mirrors; please use a mirror if possible.
Documentation
Documentation for Bash is available online, as is documentation for most GNU software. You may also find more information about Bash by running info bash or man bash, or by looking at /usr/doc/bash/, /usr/local/doc/bash/, or similar directories on your system. A brief summary is available by running bash --help.
实例
| Shell读取文件 | Shell合并文件 | 获取服务器运行时间列表 |
| 示例 | 示例 | 示例 |
| Read | while | For |
| 调试 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
脚本
批量下载
下载文本。
https://github.com/asciinema/asciinema-player/releases/download/v3.0.1/asciinema-player.css
https://github.com/asciinema/asciinema-player/releases/download/v3.0.1/asciinema-player.min.js
脚本内容。
#!/bin/bash
while read file_name file_url
do
wget -O ${file_name} -c ${file_url}
done < urls.txt
命令
| 标题文字 | 标题文字 | 标题文字 |
|---|---|---|
| $$ | 脚本本身的进程 ID (PID) | /home/kangkk echo $$ # 27326
or [jian@kang /home/kangkk]$ ps -p $$
PID TTY TIME CMD
27326 pts/0 00:00:00 bash
|
| < | 将文件的内容传递给命令的标准输入 | [jian@kang /home/kangkk]$ cat < /Users/kangjian/path/doc.txt
a
b
c
|
| << | 表示此处文档 | [jian@kang /home/kangkk]$ cat << STRING_SIGN
a
b
c
d
STRING_SIGN
a
b
c
d
可以组合命令直接将输入的文本写入文件中。 /home/kangkk cat > doc.txt << FILE
|
| <<< | 传递字符串 | [jian@kang /home/kangkk]$ cat <<< 'hi there'
hi there
|
书籍
| Advanced Bash-Scripting Guide | 示例 | 示例 |
| 示例 | 示例 | 示例 |
| 示例 | 示例 | 示例 |
No categories