Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

ash

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 ?

like image 332
Lin Avatar asked Sep 12 '25 22:09

Lin


1 Answers

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.

like image 124
Charles Duffy Avatar answered Sep 14 '25 13:09

Charles Duffy