How To Unix For Loop 1 to 100 Numbers

How To Unix For Loop 1 to 100 Numbers

To create a for loop that iterates over the numbers 1 to 100 in Unix, you can use a shell script.

Here is an example of a simple shell script that uses a for loop to print the numbers 1 to 100:

#!/bin/bash

# Iterate over the numbers 1 to 100
for i in {1..100}
do
    # Print the current number
    echo $i
done
Sourc‮www:e‬.lautturi.com

To run this script, you can save it to a file (e.g., loop.sh) and make it executable using the chmod command:

chmod +x loop.sh

Then, you can run the script using the ./ command:

./loop.sh

This will print the numbers 1 to 100 to the terminal, one number per line.

Overall, the for loop is a powerful and convenient tool for iterating over a range of values in a shell script. It can be used to perform a variety of tasks, such as processing files, performing calculations, and more.

Created Time:2017-10-29 22:08:33  Author:lautturi