Recursor
Uit Linuxdocs.nl
| Door: | Laurens Vonder |
| Versie: | 5 |
Voorwoord
In alle situaties wordt uitgegaan van het uitvoeren van commando's als root, tenzij anders aangegeven. Sudoers dienen voor elk commando 'sudo ' te plaatsen.
Recursor
Dit script laat bash commando's uitvoeren vanuit elke directory die wordt aangeduid. Die directory wordt recursief benaderd waar het uit te voeren bash commando steeds wordt herhaald.
Het gebruik is erg eenvoudig:
recursor [directory] [commando] [optie1] [optie2] [optie3]
#!/bin/bash
# Recursor: execute a bash command recursively
# Original script was a rename script. url:
# http://www.linuxquestions.org/questions/programming-9/problem-with-recursive-bash-script-538706/
# Script modified for use with all bash commands recursively
# Latest version of modified script:
# http://www.snertwerk.com
a=$2
b=$3
c=$4
d=$5
e=$6
f=$7
g=$8
h=$9
do_rename() {
[ -d "$1" ] || { echo "usage: recursor [directory] [bash command] [option1] [option2] [option3]" ; exit 1 ; }
# echo ; echo "$1 is a directory, now descending into it."
# enter this directory
cd "$1"
# preserve this directory name
local MYDIR="${PWD}"
$a $b $c $d $e $f $g $h
# make sure only the last part of a path is prepended;
# this also helps when an absolute path is passed as argument.
PREPEND=$(basename "$1")
for FILE in *
do
if [ -d "${FILE}" ] ; then
do_rename "${FILE}"
# now exit from this directory
cd "${MYDIR}"
fi
done
}
do_rename "$1"
Naar andere pagina's gaan:
Terug naar How-TO's
Terug naar Hoofdpagina

