small question of echo | grep command

Hi, i've got the following:

a=`echo $b | grep '^.*/'`

i'm storing in the variable the value of the variable b only if it has a / somewhere.
It works, but i don't want to print the value. How do i give the value of b to the grep command without the echo?

thanks!

It is not printing the value of 'b' with echo and grep in the above command you gave.

But , if it happening on your machine...
you may try the following.

echo $b >tmp
a=`grep '^.*/' tmp`
rm tmp
echo $a

Also why complicate it? The expanded regular expression grep command given, is functionally identical to grep '/'

thanks for the help!

To answer the original question....

It will not "print" the value to the terminal (if that's what you're getting at) - the output of echo is captured and stored in the variable.

I always do validation like this with an if/else construct...

my_string="/foo/bar/"
echo "$my_string" | grep '/' >/dev/null 2>&1
if [ "$?" -eq "0" ]; then
  echo "Yay"
  # use my_string for whatever you want
else
  echo "Nay"
fi

This is a (slightly verbose) piece of code that can be modified for any validation purpose....
Cheers
ZB

try ...

a=`echo $b | grep /` > /dev/null