【发布时间】:2013-12-13 19:48:02
【问题描述】:
我遇到过代码
if [ $# -eq 1 ]; then
echo "usage: Phar ~/flashmem ~/archive"
exit
fi
我以前从未遇到过[ $# -eq 1 ];,我似乎无法找到意义。它有什么作用?
【问题讨论】:
-
不幸的是,bash manual 的编写方式使得很难找到像
$#这样的东西,因为它没有显示$。$*、$@、$#等所谓的“特殊参数”在section 3.4.2, Special Parameters中。 -
Google 比 man(1)bash 更积极地去除符号也无济于事。
-
@KeithThompson:使用 Bash 手册的"entirely on one web page" 版本,
$#的第一个发现显示了所需的位置。 ;) -
@MichaelBrux:查看 git 历史记录,该更改(在描述前添加
($#))是在 2014 年 10 月 9 日在 bash-20140926 快照(提交 30595b57d9)中进行的。更改出现在 4.3 版中。不幸的是,git 历史并没有显示做了什么更改,只显示了日期快照的名称。
标签: bash shell if-statement parameters