Skip to content

Commit

Permalink
remove blank lines
Browse files Browse the repository at this point in the history
  • Loading branch information
billie66 committed Aug 30, 2014
1 parent 609aa09 commit c131550
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 57 deletions.
35 changes: 5 additions & 30 deletions book/chap27.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: book
title: 自顶向下设计
title: 自顶向下设计
---

As programs get larger and more complex, they become more difficult to design, code
Expand Down Expand Up @@ -116,7 +116,7 @@ Our script currently performs the following steps to generate the HTML document:
* Output time stamp.

* Close page body.

* Close page.

* 打开网页
Expand Down Expand Up @@ -163,13 +163,10 @@ through command substitution:
如果对于每一个任务,我们都有相应的命令,那么通过命令替换,我们就能很容易地把它们添加到我们的脚本中:

#!/bin/bash

# Program to output a system information page

TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME=$(date +"%x %r %Z")
TIME_STAMP="Generated $CURRENT_TIME, by $USER"

cat << _EOF_
<HTML>
<HEAD>
Expand All @@ -185,7 +182,6 @@ through command substitution:
</HTML>
_EOF_


We could create these additional commands two ways. We could write three separate
scripts and place them in a directory listed in our PATH, or we could embed the scripts
within our program as shell functions. As we have mentioned before, shell functions are
Expand All @@ -200,9 +196,7 @@ Shell functions have two syntactic forms:
commands
return
}

and

name () {
commands
return
Expand All @@ -228,7 +222,7 @@ Below we see a script that demonstrates the use of a shell function:
8 }
9
10 # Main program starts here
11
11
12 echo "Step 1"
13 funct
14 echo "Step 3"
Expand Down Expand Up @@ -256,25 +250,19 @@ We’ll add minimal shell function definitions to our script:
我们将给脚本添加最小的 shell 函数定义:

#!/bin/bash

# Program to output a system information page

TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME=$(date +"%x %r %Z")
TIME_STAMP="Generated $CURRENT_TIME, by $USER"

report_uptime () {
return
}

report_disk_space () {
return
}

report_home_space () {
return
}

cat << _EOF_
<HTML>
<HEAD>
Expand Down Expand Up @@ -322,30 +310,18 @@ Here is an example script that demonstrates how local variables are defined and
这里有一个实例脚本,其说明了怎样来定义和使用局部变量:

#!/bin/bash

# local-vars: script to demonstrate local variables

foo=0 # global variable foo

funct_1 () {

local foo # variable foo local to funct_1
foo=1

echo "funct_1: foo = $foo"
}

funct_2 () {

local foo # variable foo local to funct_2
foo=2

echo "funct_2: foo = $foo"

}

echo "global: foo = $foo"
funct_1
echo "global: foo = $foo"
Expand Down Expand Up @@ -412,7 +388,6 @@ If we look at the output of our script now:
<BODY>
<H1>System Information Report For linuxbox</H1>
<P>Generated 03/19/2009 04:02:10 PM EDT, by me</P>

</BODY>
</HTML>

Expand Down Expand Up @@ -540,7 +515,7 @@ df -h

### Summing Up

### 总结归纳
### 总结归纳

In this chapter, we have introduced a common method of program design called top-
down design, and we have seen how shell functions are used to build the stepwise
Expand All @@ -556,7 +531,7 @@ to be reusable by allowing them to be placed in multiple programs; a great time

### Further Reading

### 拓展阅读
### 拓展阅读

* The Wikipedia has many articles on software design philosophy. Here are a
couple of good ones:
Expand Down
31 changes: 4 additions & 27 deletions book/zh/chap27.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
layout: book-zh
title: 自顶向下设计
title: 自顶向下设计
---

随着程序变得更加庞大和复杂,设计,编码和维护它们也变得更加困难。对于任意一个大项目而言,
Expand Down Expand Up @@ -76,13 +76,10 @@ title: 自顶向下设计
如果对于每一个任务,我们都有相应的命令,那么通过命令替换,我们就能很容易地把它们添加到我们的脚本中:

#!/bin/bash

# Program to output a system information page

TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME=$(date +"%x %r %Z")
TIME_STAMP="Generated $CURRENT_TIME, by $USER"

cat << _EOF_
<HTML>
<HEAD>
Expand All @@ -106,9 +103,7 @@ title: 自顶向下设计
commands
return
}

and

name () {
commands
return
Expand All @@ -128,7 +123,7 @@ title: 自顶向下设计
8 }
9
10 # Main program starts here
11
11
12 echo "Step 1"
13 funct
14 echo "Step 3"
Expand All @@ -143,25 +138,19 @@ echo 命令。注意为了使函数调用被识别出是 shell 函数,而不
我们将给脚本添加最小的 shell 函数定义:

#!/bin/bash

# Program to output a system information page

TITLE="System Information Report For $HOSTNAME"
CURRENT_TIME=$(date +"%x %r %Z")
TIME_STAMP="Generated $CURRENT_TIME, by $USER"

report_uptime () {
return
}

report_disk_space () {
return
}

report_home_space () {
return
}

cat << _EOF_
<HTML>
<HEAD>
Expand Down Expand Up @@ -191,30 +180,18 @@ Shell 函数的命名规则和变量一样。一个函数必须至少包含一
这里有一个实例脚本,其说明了怎样来定义和使用局部变量:

#!/bin/bash

# local-vars: script to demonstrate local variables

foo=0 # global variable foo

funct_1 () {

local foo # variable foo local to funct_1
foo=1

echo "funct_1: foo = $foo"
}

funct_2 () {

local foo # variable foo local to funct_2
foo=2

echo "funct_2: foo = $foo"

}

echo "global: foo = $foo"
funct_1
echo "global: foo = $foo"
Expand Down Expand Up @@ -346,14 +323,14 @@ df -h
</div>
<br />

### 总结归纳
### 总结归纳

这一章中,我们介绍了一种常见的程序设计方法,叫做自顶向下设计,并且我们知道了怎样
使用 shell 函数按照要求来完成逐步细化的任务。我们也知道了怎样使用局部变量使 shell 函数
独立于其它函数,以及其所在程序的其它部分。这就有可能使 shell 函数以可移植的方式编写,
并且能够重复使用,通过把它们放置到多个程序中;节省了大量的时间。

### 拓展阅读
### 拓展阅读

* Wikipedia 上面有许多关于软件设计原理的文章。这里是一些好文章:

Expand Down

0 comments on commit c131550

Please sign in to comment.