IMC!


Contents


Photos

 







Browsing around...
News  News Links  Links Blog  Blog Italiano  Español 
06 - For cycle in the bash

 | 

The for..in..do..done construct allows to repeat for a given number of times a code block code1. The number of the current cycle is saved in current_cycle. After in you can write which numbers the variable current_cycle must assume. The structure is:

for current_cycle in 1 2 3 4 5; do
  code1
done

For example, to cycle 5 times, you can write:

#!/bin/bash
# This script executes 5 cycles in which the variable
# current_variable takes the values 1, 2, 3, 5, 10

for current_variable in 1 2 3 5 10; do
  echo "Current cycle: $current_variable"
done

A special element is the asterisk (*). It allows to execute for as many times as the number of files contained in the current folder.

 | 







Comments

No comment present!

Write a comment

You can write here a comment to the article you've just read. Smiles, links and images are not allowed. The maximum comment length is 4000 characters. Please be polite, all the offensive messages will be deleted.

Your comment (lascia bianco!):
Uses (max 25 characters, required)
Web site (max 255 characters, optional)
e-Mail (max 255 characters, optional, will not be published) Your opinion (lascia bianco!):
Comment (max 4000 characters, required):





Valid HTML 4.01 Transitional
E-Mail - 71.87 ms

Valid HTML 4.01 Transitional