From 85b5920550b870e2c2e3f12be27a731326da7b2a Mon Sep 17 00:00:00 2001 From: xuchunyang Date: Wed, 20 Nov 2013 23:42:29 +0800 Subject: [bash/zh-cn] chinese bash translation --- zh-cn/bash-cn.html.markdown | 148 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 148 insertions(+) create mode 100644 zh-cn/bash-cn.html.markdown (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown new file mode 100644 index 00000000..beb20479 --- /dev/null +++ b/zh-cn/bash-cn.html.markdown @@ -0,0 +1,148 @@ +--- +category: tool +tool: bash +contributors: + - ["Max Yankov", "https://github.com/golergka"] + - ["Darren Lin", "https://github.com/CogBear"] + - ["Alexandre Medeiros", "http://alemedeiros.sdf.org"] +translators: + - ["Chunyang Xu", "https://github.com/XuChunyang"] +filename: LearnBash-cn.sh +lang: zh-cn +--- + +Bash 是一个为GNU计划编写的Unix shell,是 Linux 和 Mac OS X 下的默认shell。 +以下绝大多数例子可以作为脚本的一部分也可直接在 shell 下执行。 + +[更多信息](http://www.gnu.org/software/bash/manual/bashref.html) + +```bash +#!/bin/sh +# 脚本的第一行叫 shebang,用来告知系统如何执行该脚本: +# 参见: http://en.wikipedia.org/wiki/Shebang_(Unix) +# 相信你已经明白了,注释以 # 开头,shebang 也是注释。 + +# 显示 “Hello world!” +echo Hello, world! + +# 每一句指令以换行或分号隔开: +echo 'This is the first line'; echo 'This is the second line' + +# 声明一个变量: +VARIABLE="Some string" + +# 下面是错误的做法: +VARIABLE = "Some string" +# Bash 会把 VARIABLE 当做一个指令,由于找不到该指令,因此这里会报错。 + + +# 使用变量: +echo $VARIABLE +echo "$VARIABLE" +echo '$VARIABLE' +# 当你分配 (assign) 、导出 (export),或者以其他方式使用变量时,变量名前不加 $。 +# 如果要使用变量的值, 则要加 $。 +# 注意: ' (单引号) 不会展开变量(即会屏蔽掉变量)。 + + +# 在变量内部进行字符串代换 +echo ${VARIABLE/Some/A} +# 会把 VARIABLE 中首次出现的 "some" 替换成 “A”。 + +# 内置变量: +# 下面的内置变量很有用 +echo "Last program return value: $?" +echo "Script's PID: $$" +echo "Number of arguments: $#" +echo "Scripts arguments: $@" +echo "Scripts arguments separeted in different variables: $1 $2..." + +# 获取输入: +echo "What's your name?" +read NAME # Note that we didn't need to declare new variable +echo Hello, $NAME! + +# 一般的 if 结构看起来像这样: +# 'man test' 查看更多的信息 +if [ $NAME -ne $USER ] +then + echo "Your name is you username" +else + echo "Your name isn't you username" +fi + +# 根据上一个指令执行结果决定是否执行下一个指令 +echo "Always executed" || echo "Only executed if first command fail" +echo "Always executed" && echo "Only executed if first command does NOT fail" + +# 表达式的格式如下: +echo $(( 10 + 5 )) + +# 与其他编程语言不同的是,bash 运行时依赖上下文。比如,使用 ls 时,列出当前目录。 +ls + +# 指令可以带有选项: +ls -l # Lists every file and directory on a separate line + +# 前一个指令的输出可以当作后一个指令的输入。grep 可以查找字符串。 +# 下面的指令可以,列出当前目录下所有的 txt 文件: +ls -l | grep "\.txt" + +# 重定向可以到输出,输入和错误输出。 +python2 hello.py < "input.in" +python2 hello.py > "output.out" +python2 hello.py 2> "error.err" +# > 会覆盖已存在的文件, >> 会以累加的方式输出文件中。 + +# 指令被 $( ) 嵌套在另一个指令内部: +# 以下的指令会打印当前目录下的目录和文件总数 +echo "There are $(ls | wc -l) items here." + +# Bash 的 case 语句与 Java 和 C++ 中的 switch 语句类似: +case "$VARIABLE" in + #List patterns for the conditions you want to meet + 0) echo "There is a zero.";; + 1) echo "There is a one.";; + *) echo "It is not null.";; +esac + +# 循环遍历给定的参数序列: +# 变量$VARIABLE 的值会被打印 3 次。 +# 注意 ` ` 和 $( ) 等价。seq 返回长度为 3 的数组。 +for VARIABLE in `seq 3` +do + echo "$VARIABLE" +done + +# 你也可以使用函数 +# 定义函数: +function foo () +{ + echo "Arguments work just like script arguments: $@" + echo "And: $1 $2..." + echo "This is a function" + return 0 +} + +# 更简单的方法 +bar () +{ + echo "Another way to declare functions!" + return 0 +} + +# 调用函数 +foo "My name is" $NAME + +# 有很多有用的指令需要学习: +tail -n 10 file.txt +# 打印 file.txt 的最后 10 行 +head -n 10 file.txt +# 打印 file.txt 的前 10 行 +sort file.txt +# 将 file.txt 按行排序 +uniq -d file.txt +# 报告或忽略重复的行,用选项 -d 打印重复的行 +cut -d ',' -f 1 file.txt +# 仅打印字符 ',' 之前内容(以行为单位) +``` -- cgit v1.2.3 From 22da248750815552de41367700a99eac6342e23f Mon Sep 17 00:00:00 2001 From: xuchunyang Date: Thu, 21 Nov 2013 21:52:41 +0800 Subject: [bash/zh-cn] Better translation --- zh-cn/bash-cn.html.markdown | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown index beb20479..e3eed3a6 100644 --- a/zh-cn/bash-cn.html.markdown +++ b/zh-cn/bash-cn.html.markdown @@ -11,8 +11,8 @@ filename: LearnBash-cn.sh lang: zh-cn --- -Bash 是一个为GNU计划编写的Unix shell,是 Linux 和 Mac OS X 下的默认shell。 -以下绝大多数例子可以作为脚本的一部分也可直接在 shell 下执行。 +Bash 是一个为 GNU 计划编写的 Unix shell,是 Linux 和 Mac OS X 下的默认 shell。 +以下大多数例子可以作为脚本的一部分运行也可直接在 shell 下交互执行。 [更多信息](http://www.gnu.org/software/bash/manual/bashref.html) @@ -20,7 +20,7 @@ Bash 是一个为GNU计划编写的Unix shell,是 Linux 和 Mac OS X 下的默 #!/bin/sh # 脚本的第一行叫 shebang,用来告知系统如何执行该脚本: # 参见: http://en.wikipedia.org/wiki/Shebang_(Unix) -# 相信你已经明白了,注释以 # 开头,shebang 也是注释。 +# 如你所见,注释以 # 开头,shebang 也是注释。 # 显示 “Hello world!” echo Hello, world! @@ -57,13 +57,13 @@ echo "Number of arguments: $#" echo "Scripts arguments: $@" echo "Scripts arguments separeted in different variables: $1 $2..." -# 获取输入: +# 读取输入: echo "What's your name?" -read NAME # Note that we didn't need to declare new variable +read NAME # 这里不需要声明新变量 echo Hello, $NAME! -# 一般的 if 结构看起来像这样: -# 'man test' 查看更多的信息 +# 通常的 if 结构看起来像这样: +# 'man test' 可查看更多的信息 if [ $NAME -ne $USER ] then echo "Your name is you username" @@ -82,10 +82,10 @@ echo $(( 10 + 5 )) ls # 指令可以带有选项: -ls -l # Lists every file and directory on a separate line +ls -l # 列出文件和目录的详细信息 -# 前一个指令的输出可以当作后一个指令的输入。grep 可以查找字符串。 -# 下面的指令可以,列出当前目录下所有的 txt 文件: +# 前一个指令的输出可以当作后一个指令的输入。grep 用来匹配字符串。 +# 用下面的指令列出当前目录下所有的 txt 文件: ls -l | grep "\.txt" # 重定向可以到输出,输入和错误输出。 @@ -94,13 +94,13 @@ python2 hello.py > "output.out" python2 hello.py 2> "error.err" # > 会覆盖已存在的文件, >> 会以累加的方式输出文件中。 -# 指令被 $( ) 嵌套在另一个指令内部: +# 一个指令可用 $( ) 嵌套在另一个指令内部: # 以下的指令会打印当前目录下的目录和文件总数 echo "There are $(ls | wc -l) items here." # Bash 的 case 语句与 Java 和 C++ 中的 switch 语句类似: case "$VARIABLE" in - #List patterns for the conditions you want to meet + # 列出需要匹配的字符串 0) echo "There is a zero.";; 1) echo "There is a one.";; *) echo "It is not null.";; @@ -144,5 +144,5 @@ sort file.txt uniq -d file.txt # 报告或忽略重复的行,用选项 -d 打印重复的行 cut -d ',' -f 1 file.txt -# 仅打印字符 ',' 之前内容(以行为单位) +# 打印每行中 ',' 之前内容 ``` -- cgit v1.2.3 From 48ba096ac73a07aa56799e569ba9a56264319731 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 10 Dec 2013 18:57:05 +0800 Subject: =?UTF-8?q?assign=20=E5=BA=94=E8=AF=A5=E7=BF=BB=E8=AF=91=E6=88=90?= =?UTF-8?q?=20=E8=B5=8B=E5=80=BC=20=EF=BC=8C=E8=80=8C=E9=9D=9E=20=E5=88=86?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/bash-cn.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown index e3eed3a6..fb55947d 100644 --- a/zh-cn/bash-cn.html.markdown +++ b/zh-cn/bash-cn.html.markdown @@ -40,7 +40,7 @@ VARIABLE = "Some string" echo $VARIABLE echo "$VARIABLE" echo '$VARIABLE' -# 当你分配 (assign) 、导出 (export),或者以其他方式使用变量时,变量名前不加 $。 +# 当你赋值 (assign) 、导出 (export),或者以其他方式使用变量时,变量名前不加 $。 # 如果要使用变量的值, 则要加 $。 # 注意: ' (单引号) 不会展开变量(即会屏蔽掉变量)。 -- cgit v1.2.3 From 27ae8bc889a09595898ffa7de5bb3dd6aba50ff6 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 10 Dec 2013 19:01:01 +0800 Subject: =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=A0=87=E7=82=B9=E7=AC=A6=E5=8F=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zh-cn/bash-cn.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown index e3eed3a6..e9cc7a9c 100644 --- a/zh-cn/bash-cn.html.markdown +++ b/zh-cn/bash-cn.html.markdown @@ -12,7 +12,7 @@ lang: zh-cn --- Bash 是一个为 GNU 计划编写的 Unix shell,是 Linux 和 Mac OS X 下的默认 shell。 -以下大多数例子可以作为脚本的一部分运行也可直接在 shell 下交互执行。 +以下大多数例子可以作为脚本的一部分运行,也可直接在 shell 下交互执行。 [更多信息](http://www.gnu.org/software/bash/manual/bashref.html) -- cgit v1.2.3 From 820a822081ed965be820019fce63b939876b4901 Mon Sep 17 00:00:00 2001 From: Adam Bard Date: Wed, 12 Feb 2014 12:03:31 -0800 Subject: Update bash-cn.html.markdown --- zh-cn/bash-cn.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown index 2e885833..6afa659a 100644 --- a/zh-cn/bash-cn.html.markdown +++ b/zh-cn/bash-cn.html.markdown @@ -17,7 +17,7 @@ Bash 是一个为 GNU 计划编写的 Unix shell,是 Linux 和 Mac OS X 下的 [更多信息](http://www.gnu.org/software/bash/manual/bashref.html) ```bash -#!/bin/sh +#!/bin/bash # 脚本的第一行叫 shebang,用来告知系统如何执行该脚本: # 参见: http://en.wikipedia.org/wiki/Shebang_(Unix) # 如你所见,注释以 # 开头,shebang 也是注释。 -- cgit v1.2.3 From 18a45cf7a37eb971383e3fcf65a565292e82224b Mon Sep 17 00:00:00 2001 From: Alwayswithme Date: Wed, 20 May 2015 00:14:10 +0800 Subject: update bash-cn --- zh-cn/bash-cn.html.markdown | 147 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 139 insertions(+), 8 deletions(-) (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown index 6afa659a..13f85bb7 100644 --- a/zh-cn/bash-cn.html.markdown +++ b/zh-cn/bash-cn.html.markdown @@ -5,7 +5,14 @@ contributors: - ["Max Yankov", "https://github.com/golergka"] - ["Darren Lin", "https://github.com/CogBear"] - ["Alexandre Medeiros", "http://alemedeiros.sdf.org"] + - ["Denis Arh", "https://github.com/darh"] + - ["akirahirose", "https://twitter.com/akirahirose"] + - ["Anton Strömkvist", "http://lutic.org/"] + - ["Rahil Momin", "https://github.com/iamrahil"] + - ["Gregrory Kielian", "https://github.com/gskielian"] + - ["Etan Reisner", "https://github.com/deryni"] translators: + - ["Jinchang Ye", "https://github.com/Alwayswithme"] - ["Chunyang Xu", "https://github.com/XuChunyang"] filename: LearnBash-cn.sh lang: zh-cn @@ -35,6 +42,10 @@ VARIABLE="Some string" VARIABLE = "Some string" # Bash 会把 VARIABLE 当做一个指令,由于找不到该指令,因此这里会报错。 +# 也不可以这样: +Variable= 'Some string' +# Bash 会认为 'Some string' 是一条指令,由于找不到该指令,这里再次报错。 +# (这个例子中 'Variable=' 这部分的赋值仅对 'Some string' 指令起作用。) # 使用变量: echo $VARIABLE @@ -49,6 +60,16 @@ echo '$VARIABLE' echo ${VARIABLE/Some/A} # 会把 VARIABLE 中首次出现的 "some" 替换成 “A”。 +# 变量的截取 +Length=7 +echo ${Variable:0:Length} +# 这样会仅返回变量值的前7个字符 + +# 变量的默认值 +echo ${Foo:-"DefaultValueIfFooIsMissingOrEmpty"} +# 对 null (Foo=) 和空串 (Foo="") 起作用; 零(Foo=0)时返回0 +# 注意这仅返回默认值而不是改变变量的值 + # 内置变量: # 下面的内置变量很有用 echo "Last program return value: $?" @@ -75,6 +96,17 @@ fi echo "Always executed" || echo "Only executed if first command fail" echo "Always executed" && echo "Only executed if first command does NOT fail" +# 在 if 语句中使用 && 和 || 需要多对方括号 +if [ $Name == "Steve" ] && [ $Age -eq 15 ] +then + echo "This will run if $Name is Steve AND $Age is 15." +fi + +if [ $Name == "Daniya" ] || [ $Name == "Zach" ] +then + echo "This will run if $Name is Daniya OR Zach." +fi + # 表达式的格式如下: echo $(( 10 + 5 )) @@ -88,16 +120,52 @@ ls -l # 列出文件和目录的详细信息 # 用下面的指令列出当前目录下所有的 txt 文件: ls -l | grep "\.txt" +# 重定向输入和输出(标准输入,标准输出,标准错误)。 +# 以 ^EOF$ 作为结束标记从标准输入读取数据并覆盖 hello.py : +cat > hello.py << EOF +#!/usr/bin/env python +from __future__ import print_function +import sys +print("#stdout", file=sys.stdout) +print("#stderr", file=sys.stderr) +for line in sys.stdin: + print(line, file=sys.stdout) +EOF + # 重定向可以到输出,输入和错误输出。 -python2 hello.py < "input.in" -python2 hello.py > "output.out" -python2 hello.py 2> "error.err" +python hello.py < "input.in" +python hello.py > "output.out" +python hello.py 2> "error.err" +python hello.py > "output-and-error.log" 2>&1 +python hello.py > /dev/null 2>&1 # > 会覆盖已存在的文件, >> 会以累加的方式输出文件中。 +python hello.py >> "output.out" 2>> "error.err" + +# 覆盖 output.out , 追加 error.err 并统计行数 +info bash 'Basic Shell Features' 'Redirections' > output.out 2>> error.err +wc -l output.out error.err + +# 运行指令并打印文件描述符 (比如 /dev/fd/123) +# 具体可查看: man fd +echo <(echo "#helloworld") + +# 以 "#helloworld" 覆盖 output.out: +cat > output.out <(echo "#helloworld") +echo "#helloworld" > output.out +echo "#helloworld" | cat > output.out +echo "#helloworld" | tee output.out >/dev/null + +# 清理临时文件并显示详情(增加 '-i' 选项启用交互模式) +rm -v output.out error.err output-and-error.log # 一个指令可用 $( ) 嵌套在另一个指令内部: # 以下的指令会打印当前目录下的目录和文件总数 echo "There are $(ls | wc -l) items here." +# 反引号 `` 起相同作用,但不允许嵌套 +# 优先使用 $( ). +echo "There are `ls | wc -l` items here." + # Bash 的 case 语句与 Java 和 C++ 中的 switch 语句类似: case "$VARIABLE" in # 列出需要匹配的字符串 @@ -114,6 +182,33 @@ do echo "$VARIABLE" done +# 或传统的 “for循环” : +for ((a=1; a <= 3; a++)) +do + echo $a +done + +# 也可以用于文件 +# 用 cat 输出 file1 和 file2 内容 +for Variable in file1 file2 +do + cat "$Variable" +done + +# 或作用于其他命令的输出 +# 对 ls 输出的文件执行 cat 指令。 +for Output in $(ls) +do + cat "$Output" +done + +# while 循环: +while [ true ] +do + echo "loop body here..." + break +done + # 你也可以使用函数 # 定义函数: function foo () @@ -135,14 +230,50 @@ bar () foo "My name is" $NAME # 有很多有用的指令需要学习: -tail -n 10 file.txt # 打印 file.txt 的最后 10 行 -head -n 10 file.txt +tail -n 10 file.txt # 打印 file.txt 的前 10 行 -sort file.txt +head -n 10 file.txt # 将 file.txt 按行排序 -uniq -d file.txt +sort file.txt # 报告或忽略重复的行,用选项 -d 打印重复的行 -cut -d ',' -f 1 file.txt +uniq -d file.txt # 打印每行中 ',' 之前内容 +cut -d ',' -f 1 file.txt +# 将 file.txt 文件所有 'okay' 替换为 'great', (兼容正则表达式) +sed -i 's/okay/great/g' file.txt +# 将 file.txt 中匹配正则的行打印到标准输出 +# 这里打印以 "foo" 开头, "bar" 结尾的行 +grep "^foo.*bar$" file.txt +# 使用选项 "-c" 统计行数 +grep -c "^foo.*bar$" file.txt +# 如果只是要按字面形式搜索字符串而不是按正则表达式,使用 fgrep (或 grep -F) +fgrep "^foo.*bar$" file.txt + + +# 以 bash 内建的 'help' 指令阅读 Bash 自带文档: +help +help help +help for +help return +help source +help . + +# 用 mam 指令阅读相关的 Bash 手册 +apropos bash +man 1 bash +man bash + +# 用 info 指令查阅命令的 info 文档 (info 中输入 ? 显示帮助信息) +apropos info | grep '^info.*(' +man info +info info +info 5 info + +# 阅读 Bash 的 info 文档: +info bash +info bash 'Bash Features' +info bash 6 +info --apropos bash + ``` -- cgit v1.2.3 From 59b719015a5fadf6a1d12854a19b0196c8481ec8 Mon Sep 17 00:00:00 2001 From: Alwayswithme Date: Tue, 2 Jun 2015 15:55:12 +0800 Subject: minor revision --- zh-cn/bash-cn.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown index 13f85bb7..63bec888 100644 --- a/zh-cn/bash-cn.html.markdown +++ b/zh-cn/bash-cn.html.markdown @@ -45,7 +45,7 @@ VARIABLE = "Some string" # 也不可以这样: Variable= 'Some string' # Bash 会认为 'Some string' 是一条指令,由于找不到该指令,这里再次报错。 -# (这个例子中 'Variable=' 这部分的赋值仅对 'Some string' 指令起作用。) +# (这个例子中 'Variable=' 这部分会被当作仅对 'Some string' 起作用的赋值。) # 使用变量: echo $VARIABLE @@ -264,7 +264,7 @@ apropos bash man 1 bash man bash -# 用 info 指令查阅命令的 info 文档 (info 中输入 ? 显示帮助信息) +# 用 info 指令查阅命令的 info 文档 (info 中按 ? 显示帮助信息) apropos info | grep '^info.*(' man info info info -- cgit v1.2.3 From da0d1819f85489990418713f565013f51811bdb9 Mon Sep 17 00:00:00 2001 From: Alwayswithme Date: Tue, 2 Jun 2015 16:38:11 +0800 Subject: only capitalize first character of the variable --- zh-cn/bash-cn.html.markdown | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown index 63bec888..1b79f326 100644 --- a/zh-cn/bash-cn.html.markdown +++ b/zh-cn/bash-cn.html.markdown @@ -36,11 +36,11 @@ echo Hello, world! echo 'This is the first line'; echo 'This is the second line' # 声明一个变量: -VARIABLE="Some string" +Variable="Some string" # 下面是错误的做法: -VARIABLE = "Some string" -# Bash 会把 VARIABLE 当做一个指令,由于找不到该指令,因此这里会报错。 +Variable = "Some string" +# Bash 会把 Variable 当做一个指令,由于找不到该指令,因此这里会报错。 # 也不可以这样: Variable= 'Some string' @@ -48,17 +48,17 @@ Variable= 'Some string' # (这个例子中 'Variable=' 这部分会被当作仅对 'Some string' 起作用的赋值。) # 使用变量: -echo $VARIABLE -echo "$VARIABLE" -echo '$VARIABLE' +echo $Variable +echo "$Variable" +echo '$Variable' # 当你赋值 (assign) 、导出 (export),或者以其他方式使用变量时,变量名前不加 $。 # 如果要使用变量的值, 则要加 $。 # 注意: ' (单引号) 不会展开变量(即会屏蔽掉变量)。 # 在变量内部进行字符串代换 -echo ${VARIABLE/Some/A} -# 会把 VARIABLE 中首次出现的 "some" 替换成 “A”。 +echo ${Variable/Some/A} +# 会把 Variable 中首次出现的 "some" 替换成 “A”。 # 变量的截取 Length=7 @@ -80,12 +80,12 @@ echo "Scripts arguments separeted in different variables: $1 $2..." # 读取输入: echo "What's your name?" -read NAME # 这里不需要声明新变量 -echo Hello, $NAME! +read Name # 这里不需要声明新变量 +echo Hello, $Name! # 通常的 if 结构看起来像这样: # 'man test' 可查看更多的信息 -if [ $NAME -ne $USER ] +if [ $Name -ne $USER ] then echo "Your name is you username" else @@ -167,7 +167,7 @@ echo "There are $(ls | wc -l) items here." echo "There are `ls | wc -l` items here." # Bash 的 case 语句与 Java 和 C++ 中的 switch 语句类似: -case "$VARIABLE" in +case "$Variable" in # 列出需要匹配的字符串 0) echo "There is a zero.";; 1) echo "There is a one.";; @@ -175,11 +175,11 @@ case "$VARIABLE" in esac # 循环遍历给定的参数序列: -# 变量$VARIABLE 的值会被打印 3 次。 +# 变量$Variable 的值会被打印 3 次。 # 注意 ` ` 和 $( ) 等价。seq 返回长度为 3 的数组。 -for VARIABLE in `seq 3` +for Variable in `seq 3` do - echo "$VARIABLE" + echo "$Variable" done # 或传统的 “for循环” : @@ -227,7 +227,7 @@ bar () } # 调用函数 -foo "My name is" $NAME +foo "My name is" $Name # 有很多有用的指令需要学习: # 打印 file.txt 的最后 10 行 -- cgit v1.2.3 From ee7f99fc461afad7d4aba4ac4226bdf7102abee4 Mon Sep 17 00:00:00 2001 From: Alwayswithme Date: Tue, 2 Jun 2015 17:02:23 +0800 Subject: command sync with english version --- zh-cn/bash-cn.html.markdown | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown index 1b79f326..558d9110 100644 --- a/zh-cn/bash-cn.html.markdown +++ b/zh-cn/bash-cn.html.markdown @@ -30,7 +30,7 @@ Bash 是一个为 GNU 计划编写的 Unix shell,是 Linux 和 Mac OS X 下的 # 如你所见,注释以 # 开头,shebang 也是注释。 # 显示 “Hello world!” -echo Hello, world! +echo Hello world! # 每一句指令以换行或分号隔开: echo 'This is the first line'; echo 'This is the second line' @@ -76,7 +76,7 @@ echo "Last program return value: $?" echo "Script's PID: $$" echo "Number of arguments: $#" echo "Scripts arguments: $@" -echo "Scripts arguments separeted in different variables: $1 $2..." +echo "Scripts arguments separated in different variables: $1 $2..." # 读取输入: echo "What's your name?" @@ -87,13 +87,13 @@ echo Hello, $Name! # 'man test' 可查看更多的信息 if [ $Name -ne $USER ] then - echo "Your name is you username" + echo "Your name isn't your username" else - echo "Your name isn't you username" + echo "Your name is your username" fi # 根据上一个指令执行结果决定是否执行下一个指令 -echo "Always executed" || echo "Only executed if first command fail" +echo "Always executed" || echo "Only executed if first command fails" echo "Always executed" && echo "Only executed if first command does NOT fail" # 在 if 语句中使用 && 和 || 需要多对方括号 @@ -176,8 +176,7 @@ esac # 循环遍历给定的参数序列: # 变量$Variable 的值会被打印 3 次。 -# 注意 ` ` 和 $( ) 等价。seq 返回长度为 3 的数组。 -for Variable in `seq 3` +for Variable in {1..3} do echo "$Variable" done @@ -275,5 +274,4 @@ info bash info bash 'Bash Features' info bash 6 info --apropos bash - ``` -- cgit v1.2.3 From 6aa3563465b3b9f2a9fc963f8d0b609c99d6be38 Mon Sep 17 00:00:00 2001 From: livehl Date: Thu, 10 Sep 2015 16:37:07 +0800 Subject: =?UTF-8?q?=E9=94=99=E5=88=AB=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 哎,强迫症,看到一半特意过来改了 --- zh-cn/bash-cn.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'zh-cn/bash-cn.html.markdown') diff --git a/zh-cn/bash-cn.html.markdown b/zh-cn/bash-cn.html.markdown index 558d9110..d85e5b8f 100644 --- a/zh-cn/bash-cn.html.markdown +++ b/zh-cn/bash-cn.html.markdown @@ -258,7 +258,7 @@ help return help source help . -# 用 mam 指令阅读相关的 Bash 手册 +# 用 man 指令阅读相关的 Bash 手册 apropos bash man 1 bash man bash -- cgit v1.2.3