Solaris KSH fgrep

greetings, in BASH, I have this piece of code:
ignore=$(xmllint --xpath "string(//*[local-name()='document']/*[local-name()='code']/@code)" ../Source/$core/$root/$xml)
if echo "${accept[*]}" | fgrep --word-regexp "$ignore"

Open in new window


the ignore variable stores a string.
I am checking to see if that string is in the array.
This works in BASH.

I am now forced to move to SOLARIS 10 with ksh.  --word-regexp is not available.
How do I see if the value is in the array in ksh?

Evan CutlerVolunteer Chief Information OfficerAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

woolmilkporcConnect With a Mentor Commented:
Did you really use /usr/xpg4/bin/grep ?

Anyway, >/dev/null will work (not </dev/null ...!), so you don't need -q.

-F is only needed to keep grep from interpreting what's in "$ignore" as a regular expression.

If you don't expect any regex metacharacters in that string you can omit -F as well.
In that case you never had to use "fgrep", however. grep -w would have done the trick in Linux too.

if echo "${accept[*]}" | /usr/xpg4/bin/grep -w "$ignore" >/dev/null ; then ...
Evan CutlerVolunteer Chief Information OfficerAuthor Commented:
ok...I'm do I use egrep on an array?  The example shown on the page is for a file.  THanks
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

What is the output from echo?

Looping through the array might be what you have to do to compare each element
What is the content of ignore.
Egrep can do pattern matching,
Evan CutlerVolunteer Chief Information OfficerAuthor Commented:
well the echo returns a five digit string.  say abcde
if my array has four elements to it,
I need to know if abcde is one of the items in the array.
What is the format of ignore?
If you can rearrange it as "(entry|entry2)"
echo entry |egrep "(entry|entry2)"

do you have an option to use perl instead?
Evan CutlerVolunteer Chief Information OfficerAuthor Commented:
ignore is a standard variable holding a string.  The xmllint output loads a five-digit string into the variable.

I have an array called "accept" and it's pre-loaded with a series of five-digit strings.
I need to know if $ignore is any one of the strings loaded in the array accept.
if echo "${accept[*]}" | /usr/xpg4/bin/grep -qFw "$ignore" ; then ...

("q" = quiet, I dont't think you need to see grep's output)
Evan CutlerVolunteer Chief Information OfficerAuthor Commented:
thanks...I'm getting a -F and -q option error.  ("although I agree with you").  I'm guessing SOLARIS does not like that.  does </dev/null work in this case?
Evan CutlerVolunteer Chief Information OfficerAuthor Commented:
yeah, I did, even ran it inside /usr/xpg4/bin...It' didn't like -q.
However, I am not using this is good.  thanks.
The current directory ( "." ) is most probably not contained in your PATH, and if it is, it appears most probably not before /usr/bin, the home of the standard grep.

So running a command from inside a directory generally has no effect, since the directories in PATH are the only places where executables are searched.

Thx for the points!

Try this:
if [[ ${#xx[*]} -lt ${#accept[*]} ]]
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.