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?
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