I'm working on a shell script that counts the number of each html tag in a file. Here's the part I'm having trouble with:
Code:
while getopts "df:" param
do
if test '$param = d'; then
delim=$OPTARG
elif test '$param = f'; then
files=$OPTARG
fi
done
echo $delim
echo $files
grep -oh '<[a-zA-Z0-9]\+\( [a-zA-Z0-9]\+=".\+"\)*/\?>' $files | tee list.tmp | sort -u | tee sortlist.tmp | xargs -I% grep -c % list.tmp > numbers.tmp
If, for example, I call "./tagstats -f project2.html", the while loop successfully gets the filename and the "echo $files" successfully prints it out, but when I try to use the files variable in grep, the script just hangs at the command line. In other words, grep doesn't do anything. But if I hard code the filename into the command, it does work. How can I use that files variable in grep?