Skip to content

增加$_跟>的神奇用法 #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions translations/zh-CN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,16 @@ bash中有 _非常多_ 的环境变量。你会非常频繁地遇到它们,这
| `$1 … $9` | 第1个到第9个参数列表 |
| `${10} … ${N}` | 第10个到N个参数列表 |
| `$*` or `$@` | 除了`$0`外的所有位置参数 |
| `$_` | 上一条指令的最后一个参数 |
| `$#` | 不包括`$0`在内的位置参数的个数 |
| `$FUNCNAME` | 函数名称(仅在函数内部有值) |

在下面的例子中,位置参数为:`$0='./script.sh'`,`$1='foo'`,`$2='bar'`:

./script.sh foo bar

在执行这个指令之后,`$_`的值会变成bar(`$_`多用于类似`mkdir build && cd $_`这样的场合)

变量可以有 _默认_ 值。我们可以用如下语法来指定默认值:

```bash
Expand Down Expand Up @@ -458,6 +461,9 @@ grep da * 2> errors.txt

# 从errors.txt中读取输入
less < errors.txt

# 立即删除文件并释放文件占用的空间(如果某文件正在被程序使用(比如接连不断地写log),rm不会立刻删除这个文件(于是这个log会不断地膨胀直到把你的可用空间吃干净))
> log_to_delete.log
```

## 管道
Expand Down