0
#! /bin/bash
read -p "enter i:" I
while [ $I -lt 4 ]
do
echo $I
I=$[$I+1]
done
4
  • 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? Commented Jun 11, 2020 at 13:56
  • 1
    Please take a look at editing help Commented Jun 11, 2020 at 13:57
  • "There's no output in my terminal" is what I meant by saying "It is not working." Commented Jun 11, 2020 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: stackoverflow.com/a/40048865/7939871 ) Commented Jun 11, 2020 at 14:37

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.