Ash shell - 如何在函数内执行 while 循环?

Ash shell - How to do while loop inside a function?

出于特定原因,我必须在函数内部执行无限循环,然后 运行 函数作为守护进程,

#!/bin/sh
lol(){
while true
do
    echo "looping..."
    sleep 2
done
}
lol() &

那个脚本不起作用,它给我以下错误:

/tmp/test: line 9: syntax error: unexpected "&"

如何在 ash 中的函数内执行无限循环?

你只是错误地启动了函数——这与循环无关:

lol &

括号仅在函数定义时使用,不用于调用。