Quoting Justin Krejci <jus at krytosvirus.com>:

> I think most cli utilities support using -- (two dashes) to signify  
> the end of the commands options. 
>
> Example 
>
> $ grep -- -t file.txt 
>
>
>

Thank you Justin-

I gave that a try since the script accepts single and double dash, but  
the problem remains using egrep.


Looking at the man pages I read the following, which to me means that  
the pattern can have a dash in front?

    Matching Control
        -e PATTERN, --regexp=PATTERN
               Use  PATTERN  as  the  pattern.   This  can  be  used  
to specify multiple search patterns, or to protect a pattern
               beginning with a hyphen (-).  (-e is specified by POSIX.)

Anyway, I tried with -- and added the -e switch to egrep ending with  
the same results.

I may just have to stick with an if statement. :(

SDA

> -------- Original message --------
> From: canito at dalan.us
> Date: 12/06/2013  2:09 PM  (GMT-06:00)
> To: tclug-list at mn-linux.org
> Subject: [tclug-list] Count Number of Matched Patterns
>
> In the process of writing a script which I would like to count the 
> number matched patterns (command line parameters).
>
> The issue I am running into using grep is that the string has a dash 
> in front, and it throws an error.
>
> E.g:
>
> ./script -test
>
> PATTERN=$1
>
> egrep -ic $PATTERN --> egrep: invalid option -- 't'
>
> awk and egrep work using a file, but not on a variable:
>
> EXAMPLE=`awk '/test/ { nlines++ } {print nlines}' $PATTERN`
>
> awk: cmd. line:1: fatal: cannot open file `-test' for reading (No such 
> file or directory)
>
> I know using and if command works, so am I just over doing it? What am 
> I doing wrong?
>
> if [[ $PATTERN == "-test" ]; then
>
> Thanks in advanced!
>
> Saul David Alanis
>
>
>
>
> _______________________________________________
> TCLUG Mailing List - Minneapolis/St. Paul, Minnesota
> tclug-list at mn-linux.org
> http://mailman.mn-linux.org/mailman/listinfo/tclug-list