Skip to content

Commit

Permalink
abc
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxwt committed Jun 6, 2022
1 parent 64a1657 commit c6b886c
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion website/content/ChapterOne/Fuza_Function2.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,5 +176,5 @@ exit 0

<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterOne/Fuza_Function">上一页➡️</a></p>
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterOne/">下一页➡️</a></p>
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterOne/Fuza_Function3">下一页➡️</a></p>
</div>
37 changes: 37 additions & 0 deletions website/content/ChapterOne/Fuza_Function3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
title: 1.04 函数使用重定向标准输入
type: docs
weight: 1
---

# 获取用户名
exp1:
```bash
#!/bin/bash

ARGCOUNT=1
E_ARGEXIT=65
FILE=/etc/passwd

if [ $# -ne $ARGCOUNT ]
then
echo "Usage: `basename $0` USERNAME"
exit $E_ARGEXIT
fi

find_user ()
{
while read line
do
echo "$line" | awk -F ":" '{print $5}' | grep $1
done
}<$FILE

find_user $1
exit 0
```

<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterOne/Fuza_Function2">上一页➡️</a></p>
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterOne/Fuza_Function4">下一页➡️</a></p>
</div>
32 changes: 32 additions & 0 deletions website/content/ChapterOne/Fuza_Function4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
---
title: 1.05 函数使用局部变量
type: docs
weight: 1
---

# 局部变量与全局变量
exp:
```bash
#!/bin/bash

func ()
{
local a=5
b=10
}

func

echo "\"a\" is equal $a"
echo "\"b\" is equal $b"
```
执行脚本输出
"a" is equal
"b" is equal 10

**ps:函数内没有使用local声明的变量均是全局变量**

<div style="display: flex;justify-content: space-between;align-items: center;">
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterOne/Fuza_Function3">上一页➡️</a></p>
<p><a href="https://books.linuxwt.com/linuxwtabs/ChapterOne/Fuza_Function5">下一页➡️</a></p>
</div>

0 comments on commit c6b886c

Please sign in to comment.