在bash中,为什么[1]不会失败?

puk*_*puk 3 bash shell if-statement

在shell脚本(bash)中,为什么条件得到满足

if [ 1 ]
then
 echo should not enter
fi

#Output
should not enter
Run Code Online (Sandbox Code Playgroud)

thi*_*ton 7

bash中的方括号等效test于使用括号内的参数进行调用.man test

STRING相当于-n STRING

-n STRING STRING的长度非零

,1不是空字符串.if [ 0 ],if [ false ]if [ no ]有相同的结果,但if [ "" ]没有.