Sponsored Content
Top Forums Shell Programming and Scripting if [ -z echo foo | egrep -e 'regexp' != '' ] -> dont work Post 302280536 by wiseguy on Tuesday 27th of January 2009 07:54:00 AM
Old 01-27-2009
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:
Code:
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:
Code:
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?
 

10 More Discussions You Might Find Interesting

1. Filesystems, Disks and Memory

OS X / fsck / apps dont work no control panel

Alright. My neighbor kid brings me his iBook and says nothing works. He decided to move the file system to his likeness and that semed to create the problems. Now he doesn't have access rights to his home. I have run fsck over and over again and I keep getting ** fs modified ** I have also... (0 Replies)
Discussion started by: maxwell
0 Replies

2. Shell Programming and Scripting

Find directories not containing foo, and copy foo to them

Hello all, I have a situation where I have a web root directory with a few thousand users spread out into 100 subdirectories in a 00/firstname.lastname, 01/firstname.lastname, etc. hierarchy. I suddenly need to make sure that each of these user directories contains a default index.html file... (6 Replies)
Discussion started by: dkaplowitz
6 Replies

3. UNIX for Advanced & Expert Users

why the date format dont work in crontab

Hi I tried to put a cron job which pipes the logfile appended to date +%d but it didnt work . anyone know how to make this happen thanks in advance -prasad (7 Replies)
Discussion started by: p4cldba
7 Replies

4. Shell Programming and Scripting

Substitution in a file dont work with an Array in filename

Hi. I´ve a script that should substitude the 8th line in a file called xxx.num6. The "xxx" is set by an array filled with this command: j=0 for Par in *.sys ; do Par=`echo $Par | sed 's/\(.*\).sys/\1/'` ; Par2="$Par" ; echo "${Par2}" j=$((j + 1)); done Now i try... (0 Replies)
Discussion started by: Lock3
0 Replies

5. Shell Programming and Scripting

RegExp and egrep issue

I would like to to catch the ip at the following line with egrep and regexp: ip = 192.9.110.20 and I built the following regexp to do it: (?<=ip\s=\s)\S+ when I check it with regexp simulator, it works but when I use it in the following egrep command it doesn't work - egrep -e... (2 Replies)
Discussion started by: datrigger
2 Replies

6. UNIX for Dummies Questions & Answers

keyboard and mouse dont work after sometime from boot in linux.

when i started booting linux ,after sometime both the mouse and the keyboard are getting freeze and wont respond(also the system gets hanged and all the process running dont go forward) ,nothing seem to work. Keeping in mind that it will work after sometime ,i waited for one hour also ,but... (1 Reply)
Discussion started by: sanjay.login
1 Replies

7. Shell Programming and Scripting

Simple regexp doesn't work

I'm pretty experienced with regexps, but I just can't get this expression to work. The first line of my test file is this: **** info Fri Jun 04 12:37:58 PDT 2010 stuff I'm piping this file into this: egrep '^****\s++*Fri Jun 04' This returns 0 lines. If I change the... (7 Replies)
Discussion started by: dkarr
7 Replies

8. Shell Programming and Scripting

How does egrep work?

I use grep all the time. Don't have a problem understanding it. But I am looking at a script that uses 'eprep'. Basically we have something that uses ssh to log into a remote host and execute a "df -h" and emails us. We use that to check space on remote machines. Lately I have noticed the 'egrep'... (5 Replies)
Discussion started by: brownwrap
5 Replies

9. Programming

Breakpoints dont work in Codeblocks, code does not build

Hey so I've written a program and it crashes every time I run it. I tried placing breakpoints to see what was going but to my surprise they do not work! I've placed them anywhere and they do not stop the execution of the program. In fact if I add code and hit rebuild it doesn't even build that... (1 Reply)
Discussion started by: Cambria
1 Replies

10. Programming

Shell script - if statements dont work

hi all, i have made a shell script and it runs until it reaches the if statement, doesn't the ! mean only if the command fails it will echo me that message and then exit can anyone please help me what is wrong with my code? many thanks, rob #!/bin/bash echo "is this archive... (10 Replies)
Discussion started by: robertkwild
10 Replies
echo(1B)					     SunOS/BSD Compatibility Package Commands						  echo(1B)

NAME
echo - echo arguments to standard output SYNOPSIS
/usr/ucb/echo [-n] [argument] DESCRIPTION
echo writes its arguments, separated by BLANKs and terminated by a NEWLINE, to the standard output. echo is useful for producing diagnostics in command files and for sending known data into a pipe, and for displaying the contents of envi- ronment variables. For example, you can use echo to determine how many subdirectories below the root directory (/) is your current directory, as follows: o echo your current-working-directory's full pathname o pipe the output through tr to translate the path's embedded slash-characters into space-characters o pipe that output through wc -w for a count of the names in your path. example% /usr/bin/echo "echo $PWD | tr '/' ' ' | wc -w" See tr(1) and wc(1) for their functionality. The shells csh(1), ksh(1), and sh(1), each have an echo built-in command, which, by default, will have precedence, and will be invoked if the user calls echo without a full pathname. /usr/ucb/echo and csh's echo() have an -n option, but do not understand back-slashed escape characters. sh's echo(), ksh's echo(), and /usr/bin/echo, on the other hand, understand the black-slashed escape characters, and ksh's echo() also understands a as the audible bell character; however, these commands do not have an -n option. OPTIONS
-n Do not add the NEWLINE to the output. ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +-----------------------------+-----------------------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +-----------------------------+-----------------------------+ |Availability |SUNWscpu | +-----------------------------+-----------------------------+ SEE ALSO
csh(1), echo(1), ksh(1), sh(1), tr(1), wc(1), attributes(5) NOTES
The -n option is a transition aid for BSD applications, and may not be supported in future releases. SunOS 5.11 3 Aug 1994 echo(1B)
All times are GMT -4. The time now is 09:55 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy