0
#! /bin/bash
read -p "enter i:" I
while [ $I -lt 4 ]
do
echo $I
I=$[$I+1]
done
gniourf_gniourf
  • 44,650
  • 9
  • 93
  • 104
tarang ranpara
  • 129
  • 1
  • 1
  • 7
  • 3
    what 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 Jun 11 '20 at 13:56
  • 1
    Please take a look at [editing help](http://stackoverflow.com/editing-help) – Gilles Quénot Jun 11 '20 at 13:57
  • "There's no output in my terminal" is what I meant by saying "It is not working." – tarang ranpara Jun 11 '20 at 14:37
  • 1
    Your 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: https://stackoverflow.com/a/40048865/7939871 \) – Léa Gris Jun 11 '20 at 14:37

1 Answers1

2

In modern :

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

Gilles Quénot
  • 173,512
  • 41
  • 224
  • 223