[u-u] wow, post-tested loops in sh

John Sellens jsellens at syonex.com
Mon Jul 4 14:53:21 EDT 2016


On Sun, 2016/07/03 10:12:28PM -0400, Alan J Rosenthal <flaps at 56789.ca> wrote:
| And now, my new learning gives me the following in sh as the post-tested-loop
| version (I'm not entirely sure how to indent it though):
| 
| 	i=$1
| 	while
| 	    echo $i
| 	    i=`expr $i + 1`
| 	test $i -lt 5
| 	do :
| 	done

That is kind of entertaining.  I trust you know about "break" of course?
For those that might not:

i=$1
while true; do
    echo $i
    i=`expr $i + 1`
    test $i -lt 5 || break
done


I had wanted to give an example like
    for i in `seq $1 4` ; do
    done
but that's not quite the same as your stated problem.

Hope that's interesting for someone!

John


More information about the u-u mailing list