I want to run a Unix command 100 times using a for loop from 1 to 100. Can you tell me how to take a block of numbers in a loop under KSH or BASH shell?
You can use the following syntax to run a for loop.
Ksh For Loop 1 to 100 Numbers
#!/bin/ksh # Tested with ksh version JM 93t+ 2010-03-05 for i in {1..100} do # your-unix-command-here echo $i done
Bash For Loop 1 to 100 Numbers
#!/bin/bash # Tested using bash version 4.1.5 for ((i=1;i<=100;i++)); do # your-unix-command-here echo $i done
Dealing With Older KSH88 or Bash shell
The above KSH and Bash syntax will not work on older ksh version running on HP-UX or AIX. Use the following portable syntax:
#!/usr/bin/ksh c=1 while [[ $c -le 100 ]] do # your-unix-command-here echo "$c" let c=c+1 done
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop









{ 0 comments… add one now }