Bash

De gacq wiki

Contenido

Guias

* http://db.ilug-bom.org.in/Documentation/abs-guide/

loops

 for i in `/usr/bin/seq 1 10`
 do
   /bin/echo $i
 done
 for (( i=11; i<=20; i++ ))
 do
   /bin/echo $i
 done
while test 1
do
   echo do forever
   sleep 1
done

Estructuras basicas

for i in $( ls ); do
   echo item: $i
done

         COUNTER=0
         while [  $COUNTER -lt 10 ]; do
             echo The counter is $COUNTER
             let COUNTER=COUNTER+1 
         done

         COUNTER=20
         until [  $COUNTER -lt 10 ]; do
             echo COUNTER $COUNTER
             let COUNTER-=1
         done

Functions

           #!/bin/bash 
           function quit {
               exit
           }
           function hello {
               echo Hello!
           }
           hello
           quit
           echo foo 

Functions with parameters

                #!/bin/bash 
                function quit {
                   exit
                }  
                function e {
                    echo $1 
                }  
                e Hello
                e World
                quit
                echo foo 


Alias

# busca archivos recursivamente por los directorios por contenido 
alias ff='find . -type f | xargs grep $@'
# busca procesos segun un string
alias psg='ps -ef | grep -v grep | grep $@'
Herramientas personales