Using global variable in awk (bash script)
Hello!
I'm making a script, that counts the file types listed in the arguments in a folder, like this: ./dirstat png,txt,sh -d /Home But there is a problem with it, I think in the line witch contains awk, because I'm trying to use a bash variable. I've signed the line, with big bold font. Pls help me! Thank you!! this is the code (sorry, but the comment are hungarian) : #!/bin/bash function errormsg(){ if [ $1 -eq 1 ]; then echo "A program megszámolja a fájltĂ*pusok " echo "Használat:" echo "dirstat.sh kiterjesztĂ©s1,kiterjesztĂ©s2,... -d " elif [ $1 -eq 2 ]; then echo "Hiba: Nem Ă*rhatĂł a logfájl könyvtára." elif [ $1 -eq 3 ]; then echo "Hiba: A vizsgálandĂł könyvtár jogosultságai nem" fi exit $1; } DIRECTORY="." HAVETOLOG=1; shift while [ $# -gt 0 ]; do if [ $1 = "-l" ]; then HAVETOLOG=0; shift LOGFILENAME=$1 if [ -z $LOGFILENAME ] || [ `echo -n $LOGFILENAME |cut -c 1 >/dev/null` = '-' ]; then errormsg 1; elif [ ! -w `dirname $LOGFILENAME 2>/dev/null` ]; then errormsg 2; fi elif [ $1 = "-d" ]; then shift DIRECTORY=$1 elif [ $1 = "-?" ] ; then errormsg 1 fi shift done TIP=1 I=0 for (( I=0; TIP > 0; I=I + 1)); do #I think here is the problem: TIP= `echo $1|tr "," " "|awk ' { printf $"$I" }' ` FILENUMBER=`ls -lR "$DIRECTORY" | grep "^-" |grep "\."$TIP"$"|wc -l ` OUTPUT="${DIRECTORY}/ könyvtárban ${FILENUMBER} darab ${TIP} " echo "$OUTPUT" if [ $HAVETOLOG -eq 0 ]; then echo "$OUTPUT" > $LOGFILENAME fi done exit 0 |
from the awk manpage:
Quote:
|
Thank you, but I don't understand you reply, because I'm neither good in English, nor in BAsh, so if you or somebody else has time to give me an exact solution, I would apreciate it. Thank you!:newbie:
|
All times are GMT -5. The time now is 11:03 PM. |