[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]

Newbie - shell program problem



Hi.

I have been reading "Linux Programming Bible" by Goerzen. When I try to run
the following shell program (pp 50-51), I get the error messages I have
appended. Can somebody take the trouble to explain to me why this is
happening?

TIA

Narayana

--------Program---------
#!/bin/bash

function CountMatches {
 MATCHES = `ls -d $1 2>/dev/null | wc -l`
 echo "$MATCHES"
 if   [ $MATCHES != 0 ]  ; then return 0 ; else return 1 ; fi
}

function DispMatches {
 if MATCHES=`CountMatches "$1"` ; then
  echo -n "Number of matches for $1: "
  echo $MATCHES
 else
  echo "$1 is not a valid pattern."
 fi
}

DispMatches '/dev/hda*'
DispMatches '/proc/*'
DispMatches '/foo/*'

---------Error messages----------
./func.sh: MATCHES: command not found
./func.sh: [: !=: unary operator expected
/dev/hda* is not a valid pattern.
./func.sh: MATCHES: command not found
./func.sh: [: !=: unary operator expected
/proc/* is not a valid pattern.
./func.sh: MATCHES: command not found
./func.sh: [: !=: unary operator expected
/foo/* is not a valid pattern.

PS: I am running Bash 2.