Strange error message with regex test...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Strange error message with regex test...
# 1  
Old 05-31-2006
Strange error message with regex test...

Hi all,

I have a script where i need to check the format of a string.
finally, i'm waiting a "process name" and 2 numbers separated by a ","

string like : "this_is_a_string.txt,1,10 should be ok"
string ok : "apache.exe,1,10"
string ok : "mysqld,50,0"

string not ok : "ap ache,1,10"
string not ok : "ap,ache,1,10"
string not ok : " apache,1,10"

PS : "" characters are only here to be able to show a string beginning with a space...

Here is what i tryed :

if [[ $(expr "$PROCESS_STRING" : '^[a-z0-9\-\.\_]*,[0-9]*,[0-9]*$') -ne 0 ]];
then
echo " : String OK"
else
echo " : String KO"
fi

But i always get an error :

expr: WARNING: BRE not portable: « ^[a-z0-9\-\.\_]*,[0-9]*,[0-9]*$ »: use of « ^ » character as first character of a base regular expression isn't portable; canceled.
: Format OK

The problem seems to be the "^" character at the beginning of my regex, but if i remove it, a string like " apache,1,10" would be ok but it shouldn't in my case...

thanks for your help

Florent
# 2  
Old 05-31-2006
Try the same code without "^" in ksh
Code:
if [[ $(expr "$PROCESS_STRING" : '[a-z0-9\-\.\_]*,[0-9]*,[0-9]*$') -ne 0 ]];

it shouldn't match any string with a whitespace like "ap ache,1,9" or " apache,1,9"

Regards,
Tayyab
# 3  
Old 05-31-2006
sorry, it matches if space is the first character of the string...
# 4  
Old 05-31-2006
Quote:
Originally Posted by fgilain
Hi all,

I have a script where i need to check the format of a string.
finally, i'm waiting a "process name" and 2 numbers separated by a ","

string like : "this_is_a_string.txt,1,10 should be ok"
string ok : "apache.exe,1,10"
string ok : "mysqld,50,0"

string not ok : "ap ache,1,10"
string not ok : "ap,ache,1,10"
string not ok : " apache,1,10"

PS : "" characters are only here to be able to show a string beginning with a space...

Here is what i tryed :

if [[ $(expr "$PROCESS_STRING" : '^[a-z0-9\-\.\_]*,[0-9]*,[0-9]*$') -ne 0 ]];
then
echo " : String OK"
else
echo " : String KO"
fi

But i always get an error :

expr: WARNING: BRE not portable: « ^[a-z0-9\-\.\_]*,[0-9]*,[0-9]*$ »: use of « ^ » character as first character of a base regular expression isn't portable; canceled.
: Format OK

The problem seems to be the "^" character at the beginning of my regex, but if i remove it, a string like " apache,1,10" would be ok but it shouldn't in my case...

thanks for your help

Florent
What OS are you on?
It works fine with Solaris' /usr/bin/expr and /usr/xpg4/bin/expr
# 5  
Old 05-31-2006
Using expr STRING : REGEXP performs an anchored pattern match of REGEXP in STRING. So you shouldn't need to anchor your expression with '^' or '$'.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I am getting strange message when run borne shell script

I have a code: if then#{ process daily files for file in *_${Today}*.csv *_${Today}*.txt do if || then echo "This file will be processed in separate script" continue fi if ;then ... (2 Replies)
Discussion started by: digioleg54
2 Replies

2. AIX

Really strange unix message

We are getting this message on our AIX box. No one knows where its coming from. Where can I find any information on it? Warning: file system free space is less than 10 file system total size = -2621440 file system available space = 2485160 file system used space = -5106592 file system... (3 Replies)
Discussion started by: t01scra
3 Replies

3. Programming

a strange segment fault about ltp-posix test

Hi all In the ltp-posix test,there is a case in open_posix_testsuite\conformance\interfaces\timer_gettime\speculative/6-1.c I run the above code,it will has a segment fault, if I modify it to below,it works well Anybody can tell me why? (1 Reply)
Discussion started by: yanglei_fage
1 Replies

4. Shell Programming and Scripting

regex test in bash

Hi I want to do a regex test and branch based on the test result, but this doesn't seems to work :confused: if \) ]] then echo success else echo failed fi (1 Reply)
Discussion started by: subin_bala
1 Replies

5. Shell Programming and Scripting

test command looks strange...

I just ran into this today, and don't know what to make of it... if test x$SERVER = x then echo $USAGE exit 1 fi I know what everything in there does, except for the 'x' jazz... (2 Replies)
Discussion started by: jjinno
2 Replies

6. Shell Programming and Scripting

Help regarding Error message: A test command parameter is not valid

Hi I am getting few messages when trying to run my script from the following lines in the script if test then // SomeCode fi The messages are as follows: testing.sh: OBLIGOR_GROUP_ID: 0403-012 A test command parameter is not valid. testing.sh:... (5 Replies)
Discussion started by: skyineyes
5 Replies

7. UNIX for Dummies Questions & Answers

a strange message when executing the sort command

Dear all, when I issue the command: gunzip -c file.gz |sort the command is executed normally and correctly but a message keeps appearing everytime I run the command: the message: sort: missing NEWLINE added at end of input file STDIN Does anyone know what is the meaning of this message?... (3 Replies)
Discussion started by: marwan
3 Replies

8. Shell Programming and Scripting

ed strange error message

When I start ed as regular user, following message is displayed: $ed ERROR: tempnam failed: Permission denied $ I think, following error produced in vi when search results from previous error: No previous regular expression Setting TMPDIR variable cause no effect. As root all works... (6 Replies)
Discussion started by: frenki
6 Replies
Login or Register to Ask a Question