The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
TAHI Test Suite 3.0.13 (IPv6 Conformance Test Tool branch) iBot Software Releases - RSS News 0 04-06-2008 01:20 PM
A simple find and replace without using any regex (bash) srikanths Shell Programming and Scripting 2 03-18-2008 08:08 AM
A way to use test for "$x" = [a-z] (regex) lumix Shell Programming and Scripting 9 12-16-2007 06:38 AM
Keithley Introduces Linux-Based RF Parametric Test Systems - Test and Measurement.com iBot UNIX and Linux RSS News 0 07-23-2007 11:30 AM
Strange error message with regex test... fgilain Shell Programming and Scripting 4 05-31-2006 10:52 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-16-2008
subin_bala subin_bala is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 57
Question 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

if [[ $lastele =~ \([0-9]\) ]]
then
echo success
else
echo failed
fi
  #2 (permalink)  
Old 04-16-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
  
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
You shouldn't backslash-escape the parentheses. But if your regular expression is that simple, you could also use case instead.


Code:
case $lastele in
  *[0-9]*) echo success;;
  *) echo failed >&2
esac

Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:01 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0