Click here to Skip to main content
15,444,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to take an integer value of N and using a for loop in a ubuntu linux shell print a series from 1 to N.

I cannot find anything on google which works for my system.

What I have tried so far unsuccessfully is:

for (( c=1; c<=5; c++ ))
do
echo "$c"
done

and

n=5
for val in { 1..$n }
do
echo "$val"
done

Thanks in advance.
Posted
Comments
Manfred Rudolf Bihy 29-Aug-13 14:39pm     CRLF
I hope you are aware that there are many unix shells out there, so you should at least tell us which one you are intending to use. Cheers!

1 solution

This works for me:
sh
#!bin/sh
for c in `seq 1 5`
do
echo "$c"
done


However, as Manfred noted, the right syntax depends on the shell you are using.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900