Autor Thema: Shell-Script zur Verzeichnisanalyse  (Gelesen 3370 mal)

rizor

  • Beiträge: 521
    • Profil anzeigen
Gespeichert
« am: 06. March 2010, 01:15 »
Nabend zusammen,

ich bin gerade dabei ein Shell-Script zu schreiben, dass mir eine Verzeichnisstruktur und alle Source-Files in dieser Struktur, die nicht in .nobuild stehen, in eine Datei einzutragen.
Das Script ruft sich selbst rekursiv aus.
Woran liegt es, dass es den Fehler unexpected operateor?

# parameters:
# 1. path to this shell-script

SRC=""
OBJ=""

for file in `pwd`; do
    # found the nobuild-file
    if [ $file == ".nobuild" ]; then
continue
    fi
    # found a source-file
    if [ \( -z "{$file##*.c}" -a %%file != ".c" \) -o \( -z "{$file##*.S}" -a %%file != ".S" \) ]; then
# the ".nobuild"-file exists
if [ -f ".nobuild" ]; then
    # the file could not be found in the ".nobuild"-file
    if [ $file != `grep "$file" .nobuild` ]; then
SRC="$SRC $file"
OBJ="$OBJ $file.o"
    fi
# the ".nobuild"-file does no exist
else
SRC="$SRC $file"
OBJ="$OBJ $file.o"
fi
continue
    fi
    # the file is a directory
    if [ -d $file ];then
# analyse the directory
cd $file
    sh "$1"
cd ..

# search the "file"-file and extend our SRC and OBJ
if [ -f "$file/file" ]; then
    SRC_2=`sed -ne '1p' "$file/file"`
    OBJ_2=`sed -ne '2p' "$file/file"`
    SRC="$SRC $SRC_2"
    OBJ="$OBJ $OBJ_2"
    rm -f "$file/file"
fi
    fi
done

Gruß,
rizor
Programmiertechnik:
Vermeide in Assembler zu programmieren wann immer es geht.

kevin

  • Administrator
  • Beiträge: 2 767
    • Profil anzeigen
Gespeichert
« Antwort #1 am: 06. March 2010, 09:39 »
Hast du schon probiert, dasselbe einfach mit find zu erledigen. Dürfte etwas besser performen. ;)
Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end.

rizor

  • Beiträge: 521
    • Profil anzeigen
Gespeichert
« Antwort #2 am: 06. March 2010, 12:53 »
Okay, das macht manches einfacher.
Nun habe ich aber noch das Problem, dass find mir den Pfad mit angibt "./" oder halt den gesamten Pfad.
Wie kann ich den entfernen?
Programmiertechnik:
Vermeide in Assembler zu programmieren wann immer es geht.

kevin

  • Administrator
  • Beiträge: 2 767
    • Profil anzeigen
Gespeichert
« Antwort #3 am: 06. March 2010, 13:06 »
Stört das denn? Aber du könntest find * statt find . nehmen, dann bist du den Punkt auch los. Ansonsten kannst du dir auch selber ein Ausgabeformat zusammenbasteln:
find . -printf "%P\n"
Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end.

 

Einloggen