#! /bin/bash#i=1j=$#opt=''str=''showstrings=0dir='./'parseerror=0showhelp=0testonlyfile=0testfile=''while [[ $i -le $j ]]; do # Czy wczytujemy dane dla parametru? if [[ $opt != '' ]]; then # wczytujemy vartosc dla parametru if [[ $opt == '-d' ]]; then dir=$1 opt='' elif [[ $opt == '-f' ]]; then testfile=$1 opt='' else parseerror=1 break fi # Czy sa jakies opcje elif [[ $1 == '--h' ]]; then showhelp=1 break elif [[ $1 == '-s' ]]; then # pokazywanie znalezionych ciagow showstrings=1 elif [[ $1 == '-f' ]]; then # z ta funkcja wywolujemy skrypt aby wyswietlic wynik testu pliku ;] testonlyfile=1 opt=$1 elif [[ $1 == '-d' ]]; then # katalog opt=$1 # Tutaj moze byc tylko szukany ciag - musi to byc # ostatni paramter! elif [[ "$i" == "$j" ]]; then # nasz ciag if [[ -n $opt ]]; then # ale jest pusty! parseerror=1 break fi str=$1 # Cos nie tak ze skladnia polecenia else parseerror=1 break fi # przesuwamy opcje shift 1 i=$(($i+1));done;if [[ -n $opt ]] || [[ -z $str ]]; then parseerror=1fiif [[ $parseerror == 1 ]] || [[ $showhelp == 1 ]]; then echo Użycie: findtext \[OPCJA\] \[OPCJA_2\] WZORZEC echo Wyszukuje pliki z podanym tekstem echo echo Dostępne opcje: echo \ -s\ \ wyświetla znalezione linijki na ekranie razem z nazwami plików echo \ -d ścieżka\ wymusza szukanie w podanej ścieżce zamiast w aktualnym katalogu echo echo Stworzył: Aleksander \'Ali\' Mierzwicki echo Kontakt: ali240 \/at\/ gmail \\dot\\ com exitfiif [[ $testonlyfile == 1 ]]; then if [[ -d $testfile ]]; then # katalog -> out exit fi test=`cat $testfile | grep $str`; if [[ -n $test ]]; then echo $testfile if [[ $showstrings == 1 ]]; then echo ::~~~~~~~~~ echo $test echo ::~~~~~~~~~ fi fi;else x="-exec $0" if [[ $showstrings == 1 ]]; then x="$x -s" fi x="$x -f \"{}\" \"$str\" ;" find $dir $xfi;