-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
261 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
--- | ||
title: 1.01 使用heredocument打印消息 | ||
type: docs | ||
weight: 1 | ||
--- | ||
|
||
## 打印常规消息 | ||
```bash | ||
#!/bin/bash | ||
|
||
cat << EOF | ||
------------ | ||
This is line 1 of the essage. | ||
This is line2 of the message. | ||
This is line3 of the message. | ||
This is line4 of the message | ||
This is the last line of the message. | ||
------------- | ||
EOF | ||
``` | ||
执行输出 | ||
```bash | ||
------------ | ||
This is line 1 of the essage. | ||
This is line2 of the message. | ||
This is line3 of the message. | ||
This is line4 of the message | ||
This is the last line of the message. | ||
------------- | ||
``` | ||
|
||
## 打印抑制tab消息 | ||
```bash | ||
#!/bin/bash | ||
|
||
cat <<-EOF | ||
------------ | ||
This is line 1 of the essage. | ||
This is line2 of the message. | ||
This is line3 of the message. | ||
This is line4 of the message | ||
This is the last line of the message. | ||
------------- | ||
EOF | ||
``` | ||
执行输出 | ||
```bash | ||
------------ | ||
This is line 1 of the essage. | ||
This is line2 of the message. | ||
This is line3 of the message. | ||
This is line4 of the message | ||
This is the last line of the message. | ||
------------- | ||
``` | ||
|
||
## 打印帮助信息 | ||
```bash | ||
#!/bin/bash | ||
|
||
DOC_REQUEST=80 | ||
|
||
if [ "$1" = "-h" -o "$1" = "--help" ] | ||
then | ||
cat <<EOF | ||
List the statistics of a specified directory in tabular format | ||
--------------------------------------------------------------- | ||
The command line parameter gives the directory to be listed | ||
EOF | ||
exit $DOC_REQUEST | ||
fi | ||
``` | ||
|
||
## 打印的消息输入到文件 | ||
```bash | ||
#!/bin/bash | ||
|
||
cat > newfile << EOF | ||
------------ | ||
This is line 1 of the essage. | ||
This is line2 of the message. | ||
This is line3 of the message. | ||
This is line4 of the message | ||
This is the last line of the message. | ||
------------- | ||
EOF | ||
``` | ||
|
||
|
||
|
||
<div style="display: flex;justify-content: space-between;align-items: center;"> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix">上一页➡️</a></p> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterFive/Chongdingxiang2">下一页➡️</a></p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
--- | ||
title: 1.02 Heredocument与函数 | ||
type: docs | ||
weight: 1 | ||
--- | ||
|
||
同一脚本中heredocument输出内容作为函数的输入使用 | ||
```bash | ||
#!/bin/bash | ||
|
||
|
||
geo () | ||
{ | ||
read a | ||
read b | ||
read c | ||
} | ||
|
||
geo <<EOF | ||
1 | ||
2 | ||
3 | ||
EOF | ||
|
||
echo $a $b $c | ||
exit 0 | ||
``` | ||
|
||
<div style="display: flex;justify-content: space-between;align-items: center;"> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix/Heredoc1">上一页➡️</a></p> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix/Heredoc3">下一页➡️</a></p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--- | ||
title: 1.03 Heredocument与变量 | ||
type: docs | ||
weight: 1 | ||
--- | ||
|
||
heredocument的输出保存到变量中 | ||
```bash | ||
#!/bin/bash | ||
|
||
a=$( | ||
cat <<EOF | ||
def | ||
EOF | ||
) | ||
|
||
echo $a | ||
``` | ||
|
||
<div style="display: flex;justify-content: space-between;align-items: center;"> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix/Heredoc2">上一页➡️</a></p> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix/Heredoc4">下一页➡️</a></p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
title: 1.04 Heredocument与参数替换 | ||
type: docs | ||
weight: 1 | ||
--- | ||
|
||
heredocument输出内容是可以含有变量,但是变量是否被替换取决于heredocument的limit string是否被引用 | ||
|
||
## 不被引用的情况 | ||
```bash | ||
#!/bin/bash | ||
Name="wangteng" | ||
Respondent="the author of the fine scripts" | ||
cat <<EOF | ||
hello,there ,$Name | ||
greetings to you,$Name,from $Respondent | ||
EOF | ||
|
||
exit 0 | ||
``` | ||
执行输出 | ||
```bash | ||
hello,there ,wangteng | ||
greetings to you,wangteng,from the author of the fine scripts | ||
``` | ||
|
||
## 引用的情况 | ||
```bash | ||
#!/bin/bash | ||
Name="wangteng" | ||
Respondent="the author of the fine scripts" | ||
cat <<'EOF' | ||
hello,there ,$Name | ||
greetings to you,$Name,from $Respondent | ||
EOF | ||
|
||
exit 0 | ||
``` | ||
执行输出 | ||
```bash | ||
hello,there ,$Name | ||
greetings to you,$Name,from $Respondent | ||
``` | ||
|
||
## 利用禁用参数替换的特点来实现使用脚本生成脚本或其他代码 | ||
```bash | ||
#!/bin/bash | ||
|
||
outfile=generated.sh | ||
|
||
( | ||
cat <<'EOF' | ||
#!/bin/bash | ||
echo "this is a generated shell script" | ||
echo "generated file will be named $outfile" | ||
a=7 | ||
b=3 | ||
let "c = $a * $b" | ||
echo "c = $c" | ||
exit 0 | ||
EOF | ||
) > $outfile | ||
|
||
if [ -f "$outfile" ] | ||
then | ||
chmod 755 $outfile | ||
else | ||
echo "have in creating file: \"$outfile\"" | ||
fi | ||
|
||
exit 0 | ||
``` | ||
|
||
<div style="display: flex;justify-content: space-between;align-items: center;"> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix/Heredoc2">上一页➡️</a></p> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix/Heredoc4">下一页➡️</a></p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
--- | ||
title: 1.05 使用Heredocument注释代码块 | ||
type: docs | ||
weight: 1 | ||
--- | ||
|
||
heredocument可以用来注释代码块 | ||
```bash | ||
#!/bin/bash | ||
|
||
:<<EOF | ||
echo 123 | ||
EOF | ||
echo 456 | ||
``` | ||
|
||
<div style="display: flex;justify-content: space-between;align-items: center;"> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix/Heredoc4">上一页➡️</a></p> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix/Heredoc6">下一页➡️</a></p> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
--- | ||
title: 第五章 heredocument | ||
type: docs | ||
weight: 5 | ||
--- | ||
|
||
将一段命令序列传递到一个交互程序中,例如cat ftp expect | ||
|
||
<div style="display: flex;justify-content: space-between;align-items: center;"> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterFive">上一章➡️</a></p> | ||
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterSix/Heredoc1">下一页➡️</a></p> | ||
</div> |