Reputation: 149
#! /bin/bash
read -p "enter i:" I
while [ $I -lt 4 ]
do
echo $I
I=$[$I+1]
done
Upvotes: 0
Views: 340
Reputation: 185831
In modern bash :
read -p 'enter a positive integer < 4: >>> ' int
while ((int < 4 )); do
echo "$int"
((int++))
done
((...))
is an arithmetic command, which returns an exit status of 0 if the expression is nonzero, or 1 if the expression is zero. Also used as a synonym for "let", if side effects (assignments) are needed. See http://mywiki.wooledge.org/ArithmeticExpression
Upvotes: 2