问题描述
这可能是一个非常愚蠢的问题,但是...如果[! -n"$ 1"]的意思是,如果不超过1个参数,则......这样我就能知道它是如何工作的,但是-n
是数字的缩写吗?我一直在阅读《高级bash编程指南》,他们只是开始使用它,我试图找到它,并提出它必须是内置"默认参数,第二个问题是是否有一个命令来显示默认值参数在Linux中.
This is probably a really dumb question, but... if [ ! -n "$1" ], means, if not more than 1 argument do... so I get how it works but what is -n
is it the abbreviation of number?I've been reading through The Advanced bash programming guide and they just start using it, I've tried to find it and come up with it must be a "built-in" default parameter, second question is there a command to show default parameter's in Linux.
推荐答案
test
(又名[
)的-n
参数表示不为空".您发布的示例的意思是如果$1
不为空.这是说[ -z "$1" ];
($1
为空)的一种a回方式.
The -n
argument to test
(aka [
) means "is not empty". The example you posted means "if $1
is not not empty. It's a roundabout way of saying [ -z "$1" ];
($1
is empty).
您可以通过help test
了解更多信息.
You can learn more with help test
.
$1
和其他($2
,$3
..)是位置参数.它们就是作为参数传递给您所在的脚本或函数的内容.例如,将名为foo
的脚本作为./foo bar baz
运行将导致$1 == bar
,$2 == baz
$1
and others ($2
, $3
..) are positional parameters. They're what was passed as arguments to the script or function you're in. For example, running a script named foo
as ./foo bar baz
would result in $1 == bar
, $2 == baz
这篇关于-n在Bash中是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!