- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: simple: for i in 1 2 3 4 -----> 2000
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 12:36 AM
тАО11-21-2001 12:36 AM
best way!
addition:
if i % 16 is 0 (but not for i=0) echo "/n"
Thanks,
Bill
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 01:09 AM
тАО11-21-2001 01:09 AM
Re: simple: for i in 1 2 3 4 -----> 2000
for the loop, whats wrong with this:
i=0;
while [ $i -lt 2000 ]
do
echo $i
i=`expr $i + 1`
done

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 01:10 AM
тАО11-21-2001 01:10 AM
Re: simple: for i in 1 2 3 4 -----> 2000
Thanks Bill..
d_b
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 01:10 AM
тАО11-21-2001 01:10 AM
Re: simple: for i in 1 2 3 4 -----> 2000
#!/bin/ksh
i=0
while [ $i -le 2000 ] ; do
echo $i '\c'
if [ `expr $i % 16` -eq 0 ] && [ $i -ne 0 ] ; then
echo
fi
i=`expr $i + 1`
done
Rgds, Robin.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 01:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 01:25 AM
тАО11-21-2001 01:25 AM
Re: simple: for i in 1 2 3 4 -----> 2000

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 01:46 AM
тАО11-21-2001 01:46 AM
Re: simple: for i in 1 2 3 4 -----> 2000
# /usr/bin/perl
for (1 .. 2000) {
print <<`EOF`
echo $_
EOF
}
or....
for i in `perl -e 'for (1 .. 2000) { print "$_\n" }'`
do
echo $i
done
~ Karvendhan M.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 03:35 AM
тАО11-21-2001 03:35 AM
Re: simple: for i in 1 2 3 4 -----> 2000
I ask because I've gotten _*real*_ lazy with the forums here!
I only got crowned once btw.. 4 wizard caps nearly! ;)
Later,
Bill
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 05:48 AM
тАО11-21-2001 05:48 AM
Re: simple: for i in 1 2 3 4 -----> 2000
i=`expr $i + 1`
If you have a Korn or POSIX shell script, then it is much more effective to use:
((i=$i+1))
The '((...))' construct is executed by the shell, while expr(1) is an external command, i.e. one process per iteration of the loop.
For the empty loop (2000 times), the time on my system went from 22 seconds to 0.2 seconds.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 07:37 AM
тАО11-21-2001 07:37 AM
Re: simple: for i in 1 2 3 4 -----> 2000
Frank deserves a 10 for his contribution. I tested it and he was right on. I am going to change all my scripts to use that construct where applicable.
Kudos to Frank,
C
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО11-21-2001 10:03 AM
тАО11-21-2001 10:03 AM
Re: simple: for i in 1 2 3 4 -----> 2000
typeset -Z4 i=1
while (( i < 2000 ))
do
print -n $i
(( i % 16 == 0 ))&& print
(( i += 1 ))
done
(the typeset is to neatly round make all numbers 4 digits)
I don't really think I could get it smaller without resorting to awk:
awk 'BEGIN {for (i=1;i<2000;i++) { printf "%s ",i; if (i % 16 == 0) print "" } }'
dave