#! /bin/bash
read -p "enter i:" I
while [ $I -lt 4 ]
do
echo $I
I=$[$I+1]
done
-
3what do you mean by 'not working'? do you get an error/syntx message? what output does it generate? what output are you expecting?markp-fuso– markp-fuso2020-06-11 13:56:26 +00:00Commented Jun 11, 2020 at 13:56
-
1Please take a look at editing helpGilles Quénot– Gilles Quénot2020-06-11 13:57:35 +00:00Commented Jun 11, 2020 at 13:57
-
"There's no output in my terminal" is what I meant by saying "It is not working."tarang ranpara– tarang ranpara2020-06-11 14:37:28 +00:00Commented Jun 11, 2020 at 14:37
-
1Your learning Bash shell material is too old or has not been updated. Bash arithmetic as Bracket expression has been deprecated since 1992. ( See this post: stackoverflow.com/a/40048865/7939871 )Léa Gris– Léa Gris2020-06-11 14:37:46 +00:00Commented Jun 11, 2020 at 14:37
Add a comment
|
1 Answer
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