while loop in shell script fails under 6.2-prerelease

Today I noticed a problem with the FreshPorts email processing daemon. It’s not really a daemon. It’s a shell script. After a reboot, I noticed the script was not running. Trying the script by hand, I found this error message:

.: missing filename

This sample script duplicates the problem:

#!/bin/sh
while .
do
    sleep 1
    echo slept
done

On 4.11 and 6.1, it runs fine. On FreeBSD 6.2-PRERELEASE #0: Thu Nov 9 15:30:25 EST 2006, you get the error mentioned above. I fixed the problem by using while true. I’m told that while : will work just as well, and should be more portable. : is a built in shell command. From man sh:

 :       A null command that returns a 0 (true) exit value.

I think I’ll use while : from now on.

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Comment

Scroll to Top