User Tools

Site Tools


coding:bash

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
coding:bash [2011/12/03 10:00]
tkilla created
coding:bash [2011/12/04 08:28] (current)
tkilla for loop examples
Line 1: Line 1:
 ====== bash ====== ====== bash ======
    
 +language syntax
 +
 +===== for loops =====
 +
 +   for i in 1 2 3 4 5
 +   do
 +      echo "Welcome $i times"
 +   done
 +
 +   for i in {1..5} ...
 +
 +   for i in $(seq 1 2 20)
 +
 +   for (( c=1; c<=5; c++ ))
 +
 +   if (disaster-condition)
 +   then
 +     break           # Abandon the loop.
 +   fi
 +
 +  if (condition)
 +  then
 +     continue              # Go to next iteration of I in the loop and skip statements3
 +  fi   
 +
 +  for file in /etc/*
 +  do
 +     if [ "${file}" == "/etc/resolv.conf" ]
 +     then
 +        ...
 +        break
 +     fi
 +  done
 +
 +\\
 +
 +== for loop examples: ==
 +
 +
 +**show 'disc free' space every 10sec:**
 +
 +  for i in {1..1000}; do df -h ; echo '______'; sleep 10 ; done;
 +
 +
 +**create a batch of symlinks:**
 +
 +  for i in `ls /var/www/`; do echo $i; ln -s /var/www/${i}/traffic/ /var/www/webalizer/${i}; done
 +
 +
 +**remove files, when the list of files is too long for rm:**
 +
 +
 +
 +
 +
 +
 +
 +
coding/bash.1322902821.txt.gz ยท Last modified: 2011/12/03 10:00 by tkilla