0
# !/bin/sh
i=1
while [ $i -lt 10 ]
do 
  echo $i
  i= 'expr $i + 1'
done

example program to display the numbers from 1 to 9..but it is entering into infinite loop while executing..

2 Answers 2

1

Your incrementation is causing the problem. Try this:

# !/bin/sh
i=1
while [ $i -lt 10 ]
do 
  echo $i
  i=$(( i+1 ))
done
Sign up to request clarification or add additional context in comments.

Comments

0

replace the line

i= 'expr $i + 1'

with

i=`expr $i + 1`

u used (') symbol but it is 'back quote symbol'(above tab button)and dont give space between '=' and '`' click here for code

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.