小编rah*_*rma的帖子

Shell脚本中的调用函数

我在 shell 中编写了一个简单的函数,它根据某些条件返回 0 或 1。让我称该函数名称为 foo

foo(){

...

...

}
Run Code Online (Sandbox Code Playgroud)

现在我试图在 if 条件下调用 foo 如下:-

if ( foo $1 )

...

..
Run Code Online (Sandbox Code Playgroud)

它工作正常。但是当我使用跟随方法调用时,我得到错误

if [ foo $1 ]

...

...
Run Code Online (Sandbox Code Playgroud)

为什么它会以“一元运算符预期”的形式抛出错误?

shell-script function test

5
推荐指数
1
解决办法
1564
查看次数

标签 统计

function ×1

shell-script ×1

test ×1