if [ -z echo foo | egrep -e 'regexp' != '' ] -> dont work

Hallo,

I need to test a String (a special ip number-string).

So I want to run that:

ipadress=172.0.0.0

# for debugging:
echo $ipadress | egrep -e '172\.[0-9][0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$'

# the test that doesnt work
if test -z `echo $ipadress | egrep -e '172\.[0-9][0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$'` != ""
then
  echo "match"
else
  echo "dont match"
fi

When I run this, I get the message: "dont match"
But it matchs...

But when I run this:

ipadress=nothing

# for debugging:
echo $ipadress | egrep -e '172\.[0-9][0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$'

# the test that doesnt work
if test -z `echo $ipadress | egrep -e '172\.[0-9][0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$'` != ""
then
  echo "match"
else
  echo "dont match"
fi

I get the message: "match"

Thats not what I want! But What make I wrong?

remove the ' != "" ' from your test.

Then either negate the test or use -n instead of -z.

So your test line should look like:

if ! test -z `echo $ipadress | egrep -e '172\.[0-9][0-9]?\.[0-9][0-9]?[0-9]?\.[0-9][0-9]?[0-9]?$'`