Can i use grep to check variable content correctnes?

I need to know if is possible to use grep to check content of a local variable, for eg. i use read index and i want to check if the index i read is in correct form, how do i do that i tried with grep but i get errors all the time dont know how to make it work.. thanks!

A case statement usually works best for this purpose.. What have you tried so far. Can you give an example?

Using grep, or any external command, to operate on a single line is very wasteful. Do that in a loop and you'll wonder what's making your script so slow...

Depending on your shell there's many ways to check what's in a variable. Case statements are one way. And if you have bash 3 or newer, it supports full-blown built-in regexes.

And so does ksh93,,