Linux
ID #1049
Bash - Handwerkszeug
For-Schleife
#!/bin/bash for i in $( ls ); do echo item: $i done
While-Schleife
#!/bin/bash COUNTER=0 while [ $COUNTER -lt 10 ]; do echo The counter is $COUNTER let COUNTER=COUNTER+1 done
While-Schleife zum generieren von code
find . -iname "*.avi" | while read i; do echo ffmpeg -y -i \"$i\" -ar 44100 -b 1200k \"`dirname "$i"`/`basename "$i" ".AVI"`.flv\" >> tempscript.sh; donebash tempscript.sh
While-Schleife zum ersetzen von IP in Apache-Config
grep -rl 1.2.3.4 /etc/apache2/ | while read i; do sed -i 's/1.2.3.4/4.3.2.1/g' $i; done
Until-Schleife
#!/bin/bash COUNTER=20 until [ $COUNTER -lt 10 ]; do echo COUNTER $COUNTER let COUNTER-=1 done
If-Anweisung
if [ "$1" = "text" ]; then echo "True" else echo "False" fi
If-Anweisung zum Test auf Lockfile
(alles eine Zeile ohne Umbruch)
LOCKFILE="/var/lock/script.lock" ; COMMAND="svn up /var/www/"; date;
if [ ! -f "$LOCKFILE" ] ; then echo "creating lockfile...";
touch $LOCKFILE; echo "running command \"$COMMAND\"..."; $COMMAND;
echo "removing lockfile..."; rm $LOCKFILE;
else echo "lockfile already exists...-not- running command \"$COMMAND\""; fi
Tags: Bash
Verwandte Artikel:
Letzte Änderung des Artikels: 2009-04-13 14:23
Verfasser des Artikels: Florian Schrön
Revision: 1.15
Kommentieren nicht möglich