Lin
Lin

Reputation: 1931

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

For a specific reason I have to do an infinite loop inside a function and then run the function as a daemon,

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

that script doesn't work, it gives me the following error:

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

How do I do an infinite loop inside a function in ash ?

Upvotes: 4

Views: 9115

Answers (1)

Charles Duffy
Charles Duffy

Reputation: 295687

You're just starting the function wrong -- it's nothing to do with the loop:

lol &

Parenthesis are used only at function definition time, not for invocation.

Upvotes: 3

Related Questions