0

I am bit confuse with the behavior of the FOR loop.

 #!/bin/bash
 y=5
 echo $y
 for i in {1.. $y }
 do
   echo "This is test:$i "
 done

Output:

5  
This is test:{1..5}  

Expected Output:

5  
This is test:1  
This is test:2  
This is test:3  
This is test:4  
This is test:5  
  • Shell: /bin/bash
  • BASH Version: 4.1.2
  • OS: RHEL 6.4 (Santiago)

Here I am not getting why the value of variable is not assigned in the for loop as {1..5}, if assigned why it is not iterating 5 times.

muru
  • 4,723
  • 1
  • 34
  • 78
Prabhakar
  • 237
  • 1
  • 3
  • 10

0 Answers0