Regular expression as parameter

Hello everybody, I have a problem with creating a script which allows a single parameter to be passed. Sorry if I'm not expert, I'm new at this and .

The code is

if [ "$1" = "" ]; then
        echo "Something"
        exit
fi
...does other things...
grep -i $1 $TEMPUSERS > $USERSFILE
COUNT=`wc -l $USERSFILE`
echo "Found $COUNT users"

There are two errors:
1) the grep $1 is not correctly interpreted because the expanded command doesn't have the ' delimitator.

2) There must be some error on the COUNT assignment too, because it doesn't write out the no of lines in the file.

I tried with ksh and bash shell, but it doesn't seem to be a shell type problem.
I know i'm really at the basics, but some help would be very appreciated :slight_smile:

you could add

set -x

to the beginning of your code to get some debug output. I'm not seeing anything obviously wrong with your code so more information would be needed.

grep -i "$1" $TEMPUSERS > $USERSFILE

The "" stops the interpretation of special characters.

COUNT=`wc -l < $USERSFILE`

Otherwise the filename gets printed as well.

Thank you for the help on the count, now it works :slight_smile:

As for the grep with the parameter, i resolved using egrep.

Bye!