?
Solved

Unix shell script for loop

Posted on 2014-08-20
11
Medium Priority
?
321 Views
Last Modified: 2014-08-23
I am not getting the output like
1
2
3
4
5



START=1
END=5
for i in {1..5}
do
   echo "$i"
done

----
0
Comment
Question by:digs developer
11 Comments
 
LVL 23

Expert Comment

by:nemws1
ID: 40273585
Which shell are you using?  Bash?  If so, what version?

If bash, do this to get the version:

echo $BASH_VERSION
0
 

Author Comment

by:digs developer
ID: 40273704
version
4.1.2(1)-release
0
 

Author Comment

by:digs developer
ID: 40273776
When I used below then correct output is showing.

for i in {1..5}
do
   echo "$i"
done


But my requirement is passing runtime value depending upon count.
value 5 = runtime count from file
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:digs developer
ID: 40273800
START=1
 END=5
 for i in {$start..$END}
 do
    echo "$i"
 done
0
 
LVL 18

Expert Comment

by:sventhan
ID: 40273813
it just works fine for me ..
[oracle@bosdwtst scripts]$ echo $BASH_VERSION
4.1.2(1)-release
[oracle@bosdwtst scripts]$ ./cs.sh
1
2
3
4
5
[oracle@bosdwtst scripts]$ cat cs.sh
for i in {1..5}
do
echo "$i"
done
[oracle@bosdwtst scripts]$
0
 

Author Comment

by:digs developer
ID: 40273816
Please use below code

START=1
  END=5
  for i in {$start..$END}
  do
     echo "$i"
  done
0
 
LVL 23

Expert Comment

by:nemws1
ID: 40273848
Can you just use 'seq' instead?
#!/bin/bash
START=1
END=5
for i in $(seq $START $END)
do
    echo "$i"
done

Open in new window

0
 
LVL 23

Expert Comment

by:nemws1
ID: 40273944
This will also work:
#!/bin/bash
START=1
END=5
for i in $(eval echo "{$START..$END}")
do
    echo "$i"
done

Open in new window

0
 

Author Comment

by:digs developer
ID: 40274089
Thank you so much !!
0
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 40274095
Another option:

START=1
END=5

for (( i=$START; i<=$END; i++))
 do
   echo $i
 done
0
 
LVL 62

Accepted Solution

by:
gheist earned 2000 total points
ID: 40275021
$ seq 1 5
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question