mardi 1 mars 2016

bash - multiple if clauses. What's wrong with this code?

I'm practicing writing small bash scripts. I have a habit of accidentally typing teh instead of the. So now I want to start at a directory and go through all the files there to find how many occurrences of teh there are. Here's what I have

    #!/bin/bash

    for file in `find` ; do
     if [ -f "${file}" ] ; then
      for word in `cat "${file}"` ; do
       if [ "${word}" = "teh" -o "${word}" = "Teh" ] ; then
        echo "found one"
       fi    
      done
     fi
    done

When I run it, I get

    found one
    found one
    found one
    found one
    found one
    found one
    ./findTeh: line 6: [: too many arguments

Why am I getting too many arguments. Am I not doing the if statement properly?

Thanks

Aucun commentaire:

Enregistrer un commentaire